sonixj.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  3. *
  4. * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define MODULE_NAME "sonixj"
  22. #include <linux/input.h>
  23. #include "gspca.h"
  24. #include "jpeg.h"
  25. #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
  26. MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
  27. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  28. MODULE_LICENSE("GPL");
  29. /* controls */
  30. enum e_ctrl {
  31. BRIGHTNESS,
  32. CONTRAST,
  33. COLORS,
  34. BLUE,
  35. RED,
  36. GAMMA,
  37. AUTOGAIN,
  38. HFLIP,
  39. VFLIP,
  40. SHARPNESS,
  41. INFRARED,
  42. FREQ,
  43. NCTRLS /* number of controls */
  44. };
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. struct gspca_ctrl ctrls[NCTRLS];
  49. atomic_t avg_lum;
  50. u32 exposure;
  51. u8 quality; /* image quality */
  52. #define QUALITY_MIN 60
  53. #define QUALITY_MAX 95
  54. #define QUALITY_DEF 80
  55. u8 jpegqual; /* webcam quality */
  56. u8 reg18;
  57. s8 ag_cnt;
  58. #define AG_CNT_START 13
  59. u8 bridge;
  60. #define BRIDGE_SN9C102P 0
  61. #define BRIDGE_SN9C105 1
  62. #define BRIDGE_SN9C110 2
  63. #define BRIDGE_SN9C120 3
  64. u8 sensor; /* Type of image sensor chip */
  65. u8 i2c_addr;
  66. u8 jpeg_hdr[JPEG_HDR_SZ];
  67. };
  68. enum sensors {
  69. SENSOR_ADCM1700,
  70. SENSOR_GC0307,
  71. SENSOR_HV7131R,
  72. SENSOR_MI0360,
  73. SENSOR_MI0360B,
  74. SENSOR_MO4000,
  75. SENSOR_MT9V111,
  76. SENSOR_OM6802,
  77. SENSOR_OV7630,
  78. SENSOR_OV7648,
  79. SENSOR_OV7660,
  80. SENSOR_PO1030,
  81. SENSOR_PO2030N,
  82. SENSOR_SOI768,
  83. SENSOR_SP80708,
  84. };
  85. /* V4L2 controls supported by the driver */
  86. static void setbrightness(struct gspca_dev *gspca_dev);
  87. static void setcontrast(struct gspca_dev *gspca_dev);
  88. static void setcolors(struct gspca_dev *gspca_dev);
  89. static void setredblue(struct gspca_dev *gspca_dev);
  90. static void setgamma(struct gspca_dev *gspca_dev);
  91. static void setautogain(struct gspca_dev *gspca_dev);
  92. static void sethvflip(struct gspca_dev *gspca_dev);
  93. static void setsharpness(struct gspca_dev *gspca_dev);
  94. static void setinfrared(struct gspca_dev *gspca_dev);
  95. static void setfreq(struct gspca_dev *gspca_dev);
  96. static const struct ctrl sd_ctrls[NCTRLS] = {
  97. [BRIGHTNESS] = {
  98. {
  99. .id = V4L2_CID_BRIGHTNESS,
  100. .type = V4L2_CTRL_TYPE_INTEGER,
  101. .name = "Brightness",
  102. .minimum = 0,
  103. .maximum = 0xff,
  104. .step = 1,
  105. .default_value = 0x80,
  106. },
  107. .set_control = setbrightness
  108. },
  109. [CONTRAST] = {
  110. {
  111. .id = V4L2_CID_CONTRAST,
  112. .type = V4L2_CTRL_TYPE_INTEGER,
  113. .name = "Contrast",
  114. .minimum = 0,
  115. #define CONTRAST_MAX 127
  116. .maximum = CONTRAST_MAX,
  117. .step = 1,
  118. .default_value = 63,
  119. },
  120. .set_control = setcontrast
  121. },
  122. [COLORS] = {
  123. {
  124. .id = V4L2_CID_SATURATION,
  125. .type = V4L2_CTRL_TYPE_INTEGER,
  126. .name = "Saturation",
  127. .minimum = 0,
  128. .maximum = 40,
  129. .step = 1,
  130. #define COLORS_DEF 25
  131. .default_value = COLORS_DEF,
  132. },
  133. .set_control = setcolors
  134. },
  135. [BLUE] = {
  136. {
  137. .id = V4L2_CID_BLUE_BALANCE,
  138. .type = V4L2_CTRL_TYPE_INTEGER,
  139. .name = "Blue Balance",
  140. .minimum = 24,
  141. .maximum = 40,
  142. .step = 1,
  143. .default_value = 32,
  144. },
  145. .set_control = setredblue
  146. },
  147. [RED] = {
  148. {
  149. .id = V4L2_CID_RED_BALANCE,
  150. .type = V4L2_CTRL_TYPE_INTEGER,
  151. .name = "Red Balance",
  152. .minimum = 24,
  153. .maximum = 40,
  154. .step = 1,
  155. .default_value = 32,
  156. },
  157. .set_control = setredblue
  158. },
  159. [GAMMA] = {
  160. {
  161. .id = V4L2_CID_GAMMA,
  162. .type = V4L2_CTRL_TYPE_INTEGER,
  163. .name = "Gamma",
  164. .minimum = 0,
  165. .maximum = 40,
  166. .step = 1,
  167. #define GAMMA_DEF 20
  168. .default_value = GAMMA_DEF,
  169. },
  170. .set_control = setgamma
  171. },
  172. [AUTOGAIN] = {
  173. {
  174. .id = V4L2_CID_AUTOGAIN,
  175. .type = V4L2_CTRL_TYPE_BOOLEAN,
  176. .name = "Auto Gain",
  177. .minimum = 0,
  178. .maximum = 1,
  179. .step = 1,
  180. .default_value = 1
  181. },
  182. .set_control = setautogain
  183. },
  184. [HFLIP] = {
  185. {
  186. .id = V4L2_CID_HFLIP,
  187. .type = V4L2_CTRL_TYPE_BOOLEAN,
  188. .name = "Mirror",
  189. .minimum = 0,
  190. .maximum = 1,
  191. .step = 1,
  192. .default_value = 0,
  193. },
  194. .set_control = sethvflip
  195. },
  196. [VFLIP] = {
  197. {
  198. .id = V4L2_CID_VFLIP,
  199. .type = V4L2_CTRL_TYPE_BOOLEAN,
  200. .name = "Vflip",
  201. .minimum = 0,
  202. .maximum = 1,
  203. .step = 1,
  204. .default_value = 0,
  205. },
  206. .set_control = sethvflip
  207. },
  208. [SHARPNESS] = {
  209. {
  210. .id = V4L2_CID_SHARPNESS,
  211. .type = V4L2_CTRL_TYPE_INTEGER,
  212. .name = "Sharpness",
  213. .minimum = 0,
  214. .maximum = 255,
  215. .step = 1,
  216. .default_value = 90,
  217. },
  218. .set_control = setsharpness
  219. },
  220. /* mt9v111 only */
  221. [INFRARED] = {
  222. {
  223. .id = V4L2_CID_INFRARED,
  224. .type = V4L2_CTRL_TYPE_BOOLEAN,
  225. .name = "Infrared",
  226. .minimum = 0,
  227. .maximum = 1,
  228. .step = 1,
  229. .default_value = 0,
  230. },
  231. .set_control = setinfrared
  232. },
  233. /* ov7630/ov7648/ov7660 only */
  234. [FREQ] = {
  235. {
  236. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  237. .type = V4L2_CTRL_TYPE_MENU,
  238. .name = "Light frequency filter",
  239. .minimum = 0,
  240. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  241. .step = 1,
  242. .default_value = 1,
  243. },
  244. .set_control = setfreq
  245. },
  246. };
  247. /* table of the disabled controls */
  248. static const __u32 ctrl_dis[] = {
  249. [SENSOR_ADCM1700] = (1 << AUTOGAIN) |
  250. (1 << INFRARED) |
  251. (1 << HFLIP) |
  252. (1 << VFLIP) |
  253. (1 << FREQ),
  254. [SENSOR_GC0307] = (1 << INFRARED) |
  255. (1 << HFLIP) |
  256. (1 << VFLIP) |
  257. (1 << FREQ),
  258. [SENSOR_HV7131R] = (1 << INFRARED) |
  259. (1 << HFLIP) |
  260. (1 << FREQ),
  261. [SENSOR_MI0360] = (1 << INFRARED) |
  262. (1 << HFLIP) |
  263. (1 << VFLIP) |
  264. (1 << FREQ),
  265. [SENSOR_MI0360B] = (1 << INFRARED) |
  266. (1 << HFLIP) |
  267. (1 << VFLIP) |
  268. (1 << FREQ),
  269. [SENSOR_MO4000] = (1 << INFRARED) |
  270. (1 << HFLIP) |
  271. (1 << VFLIP) |
  272. (1 << FREQ),
  273. [SENSOR_MT9V111] = (1 << HFLIP) |
  274. (1 << VFLIP) |
  275. (1 << FREQ),
  276. [SENSOR_OM6802] = (1 << INFRARED) |
  277. (1 << HFLIP) |
  278. (1 << VFLIP) |
  279. (1 << FREQ),
  280. [SENSOR_OV7630] = (1 << INFRARED) |
  281. (1 << HFLIP),
  282. [SENSOR_OV7648] = (1 << INFRARED) |
  283. (1 << HFLIP),
  284. [SENSOR_OV7660] = (1 << AUTOGAIN) |
  285. (1 << INFRARED) |
  286. (1 << HFLIP) |
  287. (1 << VFLIP),
  288. [SENSOR_PO1030] = (1 << AUTOGAIN) |
  289. (1 << INFRARED) |
  290. (1 << HFLIP) |
  291. (1 << VFLIP) |
  292. (1 << FREQ),
  293. [SENSOR_PO2030N] = (1 << AUTOGAIN) |
  294. (1 << INFRARED) |
  295. (1 << FREQ),
  296. [SENSOR_SOI768] = (1 << AUTOGAIN) |
  297. (1 << INFRARED) |
  298. (1 << HFLIP) |
  299. (1 << VFLIP) |
  300. (1 << FREQ),
  301. [SENSOR_SP80708] = (1 << AUTOGAIN) |
  302. (1 << INFRARED) |
  303. (1 << HFLIP) |
  304. (1 << VFLIP) |
  305. (1 << FREQ),
  306. };
  307. static const struct v4l2_pix_format cif_mode[] = {
  308. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  309. .bytesperline = 352,
  310. .sizeimage = 352 * 288 * 4 / 8 + 590,
  311. .colorspace = V4L2_COLORSPACE_JPEG,
  312. .priv = 0},
  313. };
  314. static const struct v4l2_pix_format vga_mode[] = {
  315. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  316. .bytesperline = 160,
  317. .sizeimage = 160 * 120 * 4 / 8 + 590,
  318. .colorspace = V4L2_COLORSPACE_JPEG,
  319. .priv = 2},
  320. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  321. .bytesperline = 320,
  322. .sizeimage = 320 * 240 * 3 / 8 + 590,
  323. .colorspace = V4L2_COLORSPACE_JPEG,
  324. .priv = 1},
  325. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  326. .bytesperline = 640,
  327. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  328. .sizeimage = 640 * 480 * 3 / 4 + 590,
  329. .colorspace = V4L2_COLORSPACE_JPEG,
  330. .priv = 0},
  331. };
  332. static const u8 sn_adcm1700[0x1c] = {
  333. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  334. 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
  335. /* reg8 reg9 rega regb regc regd rege regf */
  336. 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  337. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  338. 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
  339. /* reg18 reg19 reg1a reg1b */
  340. 0x06, 0x00, 0x00, 0x00
  341. };
  342. static const u8 sn_gc0307[0x1c] = {
  343. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  344. 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
  345. /* reg8 reg9 rega regb regc regd rege regf */
  346. 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  347. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  348. 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
  349. /* reg18 reg19 reg1a reg1b */
  350. 0x06, 0x00, 0x00, 0x00
  351. };
  352. static const u8 sn_hv7131[0x1c] = {
  353. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  354. 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  355. /* reg8 reg9 rega regb regc regd rege regf */
  356. 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  357. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  358. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  359. /* reg18 reg19 reg1a reg1b */
  360. 0x0a, 0x00, 0x00, 0x00
  361. };
  362. static const u8 sn_mi0360[0x1c] = {
  363. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  364. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  365. /* reg8 reg9 rega regb regc regd rege regf */
  366. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  367. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  368. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  369. /* reg18 reg19 reg1a reg1b */
  370. 0x06, 0x00, 0x00, 0x00
  371. };
  372. static const u8 sn_mi0360b[0x1c] = {
  373. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  374. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  375. /* reg8 reg9 rega regb regc regd rege regf */
  376. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  377. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  378. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x40,
  379. /* reg18 reg19 reg1a reg1b */
  380. 0x06, 0x00, 0x00, 0x00
  381. };
  382. static const u8 sn_mo4000[0x1c] = {
  383. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  384. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  385. /* reg8 reg9 rega regb regc regd rege regf */
  386. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  387. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  388. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  389. /* reg18 reg19 reg1a reg1b */
  390. 0x08, 0x00, 0x00, 0x00
  391. };
  392. static const u8 sn_mt9v111[0x1c] = {
  393. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  394. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  395. /* reg8 reg9 rega regb regc regd rege regf */
  396. 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  397. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  398. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  399. /* reg18 reg19 reg1a reg1b */
  400. 0x06, 0x00, 0x00, 0x00
  401. };
  402. static const u8 sn_om6802[0x1c] = {
  403. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  404. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
  405. /* reg8 reg9 rega regb regc regd rege regf */
  406. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  407. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  408. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  409. /* reg18 reg19 reg1a reg1b */
  410. 0x05, 0x00, 0x00, 0x00
  411. };
  412. static const u8 sn_ov7630[0x1c] = {
  413. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  414. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  415. /* reg8 reg9 rega regb regc regd rege regf */
  416. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  417. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  418. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  419. /* reg18 reg19 reg1a reg1b */
  420. 0x0b, 0x00, 0x00, 0x00
  421. };
  422. static const u8 sn_ov7648[0x1c] = {
  423. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  424. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  425. /* reg8 reg9 rega regb regc regd rege regf */
  426. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  427. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  428. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  429. /* reg18 reg19 reg1a reg1b */
  430. 0x0b, 0x00, 0x00, 0x00
  431. };
  432. static const u8 sn_ov7660[0x1c] = {
  433. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  434. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  435. /* reg8 reg9 rega regb regc regd rege regf */
  436. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  437. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  438. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  439. /* reg18 reg19 reg1a reg1b */
  440. 0x07, 0x00, 0x00, 0x00
  441. };
  442. static const u8 sn_po1030[0x1c] = {
  443. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  444. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  445. /* reg8 reg9 rega regb regc regd rege regf */
  446. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  447. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  448. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
  449. /* reg18 reg19 reg1a reg1b */
  450. 0x07, 0x00, 0x00, 0x00
  451. };
  452. static const u8 sn_po2030n[0x1c] = {
  453. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  454. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  455. /* reg8 reg9 rega regb regc regd rege regf */
  456. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  457. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  458. 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
  459. /* reg18 reg19 reg1a reg1b */
  460. 0x07, 0x00, 0x00, 0x00
  461. };
  462. static const u8 sn_soi768[0x1c] = {
  463. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  464. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  465. /* reg8 reg9 rega regb regc regd rege regf */
  466. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  467. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  468. 0x03, 0x00, 0x00, 0x01, 0x08, 0x28, 0x1e, 0x00,
  469. /* reg18 reg19 reg1a reg1b */
  470. 0x07, 0x00, 0x00, 0x00
  471. };
  472. static const u8 sn_sp80708[0x1c] = {
  473. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  474. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  475. /* reg8 reg9 rega regb regc regd rege regf */
  476. 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  477. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  478. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  479. /* reg18 reg19 reg1a reg1b */
  480. 0x07, 0x00, 0x00, 0x00
  481. };
  482. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  483. static const u8 *sn_tb[] = {
  484. [SENSOR_ADCM1700] = sn_adcm1700,
  485. [SENSOR_GC0307] = sn_gc0307,
  486. [SENSOR_HV7131R] = sn_hv7131,
  487. [SENSOR_MI0360] = sn_mi0360,
  488. [SENSOR_MI0360B] = sn_mi0360b,
  489. [SENSOR_MO4000] = sn_mo4000,
  490. [SENSOR_MT9V111] = sn_mt9v111,
  491. [SENSOR_OM6802] = sn_om6802,
  492. [SENSOR_OV7630] = sn_ov7630,
  493. [SENSOR_OV7648] = sn_ov7648,
  494. [SENSOR_OV7660] = sn_ov7660,
  495. [SENSOR_PO1030] = sn_po1030,
  496. [SENSOR_PO2030N] = sn_po2030n,
  497. [SENSOR_SOI768] = sn_soi768,
  498. [SENSOR_SP80708] = sn_sp80708,
  499. };
  500. /* default gamma table */
  501. static const u8 gamma_def[17] = {
  502. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  503. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  504. };
  505. /* gamma for sensor ADCM1700 */
  506. static const u8 gamma_spec_0[17] = {
  507. 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
  508. 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
  509. };
  510. /* gamma for sensors HV7131R and MT9V111 */
  511. static const u8 gamma_spec_1[17] = {
  512. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  513. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  514. };
  515. /* gamma for sensor GC0307 */
  516. static const u8 gamma_spec_2[17] = {
  517. 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
  518. 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
  519. };
  520. /* gamma for sensor SP80708 */
  521. static const u8 gamma_spec_3[17] = {
  522. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  523. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  524. };
  525. /* color matrix and offsets */
  526. static const u8 reg84[] = {
  527. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  528. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  529. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  530. 0x00, 0x00, 0x00 /* YUV offsets */
  531. };
  532. #define DELAY 0xdd
  533. static const u8 adcm1700_sensor_init[][8] = {
  534. {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
  535. {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
  536. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  537. {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  538. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  539. {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
  540. {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
  541. {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
  542. {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
  543. {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
  544. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  545. {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
  546. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  547. {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
  548. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  549. {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
  550. {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  551. {}
  552. };
  553. static const u8 adcm1700_sensor_param1[][8] = {
  554. {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
  555. {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
  556. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  557. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  558. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  559. {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
  560. {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
  561. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  562. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  563. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  564. {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
  565. {}
  566. };
  567. static const u8 gc0307_sensor_init[][8] = {
  568. {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
  569. {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
  570. {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
  571. {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
  572. {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  573. {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  574. {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  575. {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
  576. {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  577. {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  578. {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
  579. {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
  580. {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
  581. {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
  582. {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
  583. {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
  584. {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
  585. {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
  586. {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
  587. {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
  588. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
  589. {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
  590. {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
  591. {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
  592. {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
  593. {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
  594. {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
  595. {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
  596. {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
  597. {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
  598. {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
  599. {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
  600. {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  601. {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
  602. {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
  603. {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
  604. {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
  605. {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
  606. {}
  607. };
  608. static const u8 gc0307_sensor_param1[][8] = {
  609. {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
  610. {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
  611. {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
  612. {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
  613. /*param3*/
  614. {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
  615. {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
  616. {}
  617. };
  618. static const u8 hv7131r_sensor_init[][8] = {
  619. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  620. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  621. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  622. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  623. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  624. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  625. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  626. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  627. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  628. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  629. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  630. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  631. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  632. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  633. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  634. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  635. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  636. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  637. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  638. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  639. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  640. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  641. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  642. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  643. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  644. {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
  645. /* set sensor clock */
  646. {}
  647. };
  648. static const u8 mi0360_sensor_init[][8] = {
  649. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  650. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  651. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  652. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  653. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  654. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  655. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  656. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  657. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  658. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  659. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  660. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  661. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  662. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  663. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  664. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  665. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  666. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  667. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  668. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  669. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  670. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  671. {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
  672. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  673. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  674. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  675. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  676. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  677. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  678. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  679. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  680. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  681. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  682. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  683. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  684. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  685. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  686. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  687. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  688. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  689. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  690. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  691. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  692. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  693. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  694. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  695. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  696. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  697. {}
  698. };
  699. static const u8 mi0360b_sensor_init[][8] = {
  700. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  701. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  702. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  703. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  704. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  705. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  706. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  707. {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  708. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  709. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  710. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  711. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  712. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  713. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  714. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  715. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  716. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  717. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  718. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  719. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  720. {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  721. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  722. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  723. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  724. {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
  725. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  726. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  727. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  728. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  729. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  730. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  731. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  732. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  733. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  734. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  735. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  736. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  737. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  738. {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
  739. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
  740. {}
  741. };
  742. static const u8 mi0360b_sensor_param1[][8] = {
  743. {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  744. {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
  745. {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
  746. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  747. {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
  748. {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
  749. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  750. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  751. {}
  752. };
  753. static const u8 mo4000_sensor_init[][8] = {
  754. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  755. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  756. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  757. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  758. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  759. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  760. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  761. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  762. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  763. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  764. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  765. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  766. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  767. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  768. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  769. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  770. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  771. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  772. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  773. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  774. {}
  775. };
  776. static const u8 mt9v111_sensor_init[][8] = {
  777. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  778. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  779. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  780. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  781. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  782. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  783. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  784. {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
  785. {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
  786. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  787. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  788. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  789. {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
  790. {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
  791. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  792. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  793. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  794. {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
  795. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  796. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  797. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  798. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  799. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  800. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  801. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  802. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  803. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  804. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  805. {}
  806. };
  807. static const u8 mt9v111_sensor_param1[][8] = {
  808. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  809. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  810. {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
  811. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
  812. {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
  813. /*******/
  814. {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
  815. {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
  816. {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
  817. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  818. {}
  819. };
  820. static const u8 om6802_init0[2][8] = {
  821. /*fixme: variable*/
  822. {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
  823. {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
  824. };
  825. static const u8 om6802_sensor_init[][8] = {
  826. {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
  827. /* factory mode */
  828. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  829. /* output raw RGB */
  830. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  831. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  832. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  833. /* auto-exposure speed (0) / white balance mode (auto RGB) */
  834. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  835. * set color mode */
  836. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  837. * max AGC value in AE */
  838. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  839. * preset AGC */
  840. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  841. * preset brightness */
  842. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  843. * preset contrast */
  844. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  845. * preset gamma */
  846. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  847. /* luminance mode (0x4f -> AutoExpo on) */
  848. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  849. /* preset shutter */
  850. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  851. * auto frame rate */
  852. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  853. {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  854. {}
  855. };
  856. static const u8 om6802_sensor_param1[][8] = {
  857. {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
  858. {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
  859. {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
  860. {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
  861. {}
  862. };
  863. static const u8 ov7630_sensor_init[][8] = {
  864. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  865. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  866. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  867. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  868. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  869. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  870. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  871. /* win: i2c_r from 00 to 80 */
  872. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  873. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  874. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  875. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  876. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  877. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  878. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  879. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  880. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  881. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  882. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  883. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  884. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  885. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  886. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  887. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  888. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  889. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  890. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  891. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  892. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  893. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  894. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  895. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  896. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  897. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  898. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  899. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  900. {}
  901. };
  902. static const u8 ov7630_sensor_param1[][8] = {
  903. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  904. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  905. /*fixme: + 0x12, 0x04*/
  906. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  907. * set by setvflip */
  908. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  909. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  910. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  911. /* */
  912. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  913. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  914. /* */
  915. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  916. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  917. {}
  918. };
  919. static const u8 ov7648_sensor_init[][8] = {
  920. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  921. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  922. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  923. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  924. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  925. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  926. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  927. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  928. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  929. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  930. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  931. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  932. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  933. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  934. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  935. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  936. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  937. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  938. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  939. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  940. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  941. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  942. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  943. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  944. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  945. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  946. {}
  947. };
  948. static const u8 ov7648_sensor_param1[][8] = {
  949. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  950. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  951. * set by setvflip */
  952. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  953. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  954. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  955. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  956. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  957. /*...*/
  958. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  959. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  960. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  961. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  962. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  963. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  964. {}
  965. };
  966. static const u8 ov7660_sensor_init[][8] = {
  967. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  968. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  969. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  970. /* Outformat = rawRGB */
  971. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  972. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  973. /* GAIN BLUE RED VREF */
  974. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  975. /* COM 1 BAVE GEAVE AECHH */
  976. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  977. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  978. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  979. /* AECH CLKRC COM7 COM8 */
  980. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  981. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  982. /* HSTART HSTOP VSTRT VSTOP */
  983. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  984. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  985. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  986. /* BOS GBOS GROS ROS (BGGR offset) */
  987. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  988. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  989. /* AEW AEB VPT BBIAS */
  990. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  991. /* GbBIAS RSVD EXHCH EXHCL */
  992. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  993. /* RBIAS ADVFL ASDVFH YAVE */
  994. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  995. /* HSYST HSYEN HREF */
  996. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  997. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  998. /* ADC ACOM OFON TSLB */
  999. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  1000. /* COM11 COM12 COM13 COM14 */
  1001. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  1002. /* EDGE COM15 COM16 COM17 */
  1003. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  1004. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  1005. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1006. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  1007. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  1008. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  1009. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  1010. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  1011. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1012. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  1013. /* LCC1 LCC2 LCC3 LCC4 */
  1014. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  1015. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  1016. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1017. /* band gap reference [0:3] DBLV */
  1018. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  1019. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  1020. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  1021. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  1022. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  1023. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  1024. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  1025. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  1026. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  1027. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  1028. /* not in all ms-win traces*/
  1029. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  1030. {}
  1031. };
  1032. static const u8 ov7660_sensor_param1[][8] = {
  1033. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  1034. /* bits[3..0]reserved */
  1035. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  1036. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1037. /* VREF vertical frame ctrl */
  1038. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1039. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  1040. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  1041. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  1042. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  1043. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  1044. /****** (some exchanges in the win trace) ******/
  1045. /*fixme:param2*/
  1046. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  1047. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  1048. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  1049. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  1050. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  1051. /****** (some exchanges in the win trace) ******/
  1052. /******!! startsensor KO if changed !!****/
  1053. /*fixme: param3*/
  1054. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  1055. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  1056. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1057. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  1058. {}
  1059. };
  1060. static const u8 po1030_sensor_init[][8] = {
  1061. /* the sensor registers are described in m5602/m5602_po1030.h */
  1062. {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
  1063. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  1064. {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1065. {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1066. {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
  1067. {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  1068. {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
  1069. {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  1070. {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
  1071. {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
  1072. {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
  1073. {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
  1074. {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  1075. {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1076. {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
  1077. {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
  1078. {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
  1079. {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
  1080. {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
  1081. {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
  1082. {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  1083. {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  1084. {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
  1085. {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
  1086. {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
  1087. {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
  1088. {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1089. {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
  1090. {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  1091. {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  1092. {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1093. {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1094. {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
  1095. {}
  1096. };
  1097. static const u8 po1030_sensor_param1[][8] = {
  1098. /* from ms-win traces - these values change with auto gain/expo/wb.. */
  1099. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1100. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1101. /* mean values */
  1102. {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
  1103. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
  1104. {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
  1105. {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
  1106. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
  1107. {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1108. /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
  1109. {}
  1110. };
  1111. static const u8 po2030n_sensor_init[][8] = {
  1112. {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
  1113. {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
  1114. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1115. {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1116. {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
  1117. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1118. {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
  1119. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1120. {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
  1121. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1122. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1123. {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
  1124. {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
  1125. {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
  1126. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1127. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
  1128. {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
  1129. {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1130. {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  1131. {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
  1132. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
  1133. {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1134. {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
  1135. {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
  1136. {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
  1137. {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
  1138. {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
  1139. {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
  1140. {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
  1141. {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1142. {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
  1143. {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
  1144. {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
  1145. {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1146. {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
  1147. {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
  1148. {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
  1149. {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1150. {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
  1151. {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
  1152. {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
  1153. {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1154. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1155. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
  1156. {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
  1157. {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
  1158. {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
  1159. {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
  1160. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
  1161. {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
  1162. {}
  1163. };
  1164. static const u8 po2030n_sensor_param1[][8] = {
  1165. {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
  1166. {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
  1167. {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
  1168. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1169. {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10},
  1170. /*param2*/
  1171. {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1172. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1173. {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
  1174. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1175. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1176. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1177. {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10},
  1178. /*after start*/
  1179. {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1180. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1181. {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10},
  1182. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1183. {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10},
  1184. {}
  1185. };
  1186. static const u8 soi768_sensor_init[][8] = {
  1187. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  1188. {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
  1189. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  1190. {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
  1191. {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
  1192. {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
  1193. {}
  1194. };
  1195. static const u8 soi768_sensor_param1[][8] = {
  1196. {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
  1197. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1198. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1199. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1200. {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
  1201. /* */
  1202. /* {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1203. /* {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
  1204. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1205. /* {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1206. {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
  1207. /* the next sequence should be used for auto gain */
  1208. {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
  1209. /* global gain ? : 07 - change with 0x15 at the end */
  1210. {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
  1211. {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
  1212. {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
  1213. /* exposure ? : 0200 - change with 0x1e at the end */
  1214. {}
  1215. };
  1216. static const u8 sp80708_sensor_init[][8] = {
  1217. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  1218. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  1219. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1220. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1221. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1222. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1223. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  1224. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  1225. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  1226. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  1227. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  1228. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  1229. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  1230. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  1231. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  1232. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  1233. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  1234. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  1235. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  1236. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  1237. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  1238. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  1239. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  1240. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  1241. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  1242. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1243. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  1244. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  1245. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  1246. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  1247. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  1248. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  1249. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  1250. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  1251. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  1252. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  1253. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  1254. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  1255. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  1256. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  1257. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  1258. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  1259. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  1260. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1261. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  1262. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  1263. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  1264. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  1265. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  1266. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  1267. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  1268. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  1269. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  1270. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  1271. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  1272. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1273. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  1274. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  1275. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  1276. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  1277. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  1278. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1279. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  1280. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  1281. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  1282. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  1283. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  1284. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  1285. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  1286. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  1287. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  1288. {}
  1289. };
  1290. static const u8 sp80708_sensor_param1[][8] = {
  1291. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1292. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1293. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  1294. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  1295. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  1296. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  1297. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  1298. {}
  1299. };
  1300. static const u8 (*sensor_init[])[8] = {
  1301. [SENSOR_ADCM1700] = adcm1700_sensor_init,
  1302. [SENSOR_GC0307] = gc0307_sensor_init,
  1303. [SENSOR_HV7131R] = hv7131r_sensor_init,
  1304. [SENSOR_MI0360] = mi0360_sensor_init,
  1305. [SENSOR_MI0360B] = mi0360b_sensor_init,
  1306. [SENSOR_MO4000] = mo4000_sensor_init,
  1307. [SENSOR_MT9V111] = mt9v111_sensor_init,
  1308. [SENSOR_OM6802] = om6802_sensor_init,
  1309. [SENSOR_OV7630] = ov7630_sensor_init,
  1310. [SENSOR_OV7648] = ov7648_sensor_init,
  1311. [SENSOR_OV7660] = ov7660_sensor_init,
  1312. [SENSOR_PO1030] = po1030_sensor_init,
  1313. [SENSOR_PO2030N] = po2030n_sensor_init,
  1314. [SENSOR_SOI768] = soi768_sensor_init,
  1315. [SENSOR_SP80708] = sp80708_sensor_init,
  1316. };
  1317. /* read <len> bytes to gspca_dev->usb_buf */
  1318. static void reg_r(struct gspca_dev *gspca_dev,
  1319. u16 value, int len)
  1320. {
  1321. int ret;
  1322. if (gspca_dev->usb_err < 0)
  1323. return;
  1324. #ifdef GSPCA_DEBUG
  1325. if (len > USB_BUF_SZ) {
  1326. err("reg_r: buffer overflow");
  1327. return;
  1328. }
  1329. #endif
  1330. ret = usb_control_msg(gspca_dev->dev,
  1331. usb_rcvctrlpipe(gspca_dev->dev, 0),
  1332. 0,
  1333. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1334. value, 0,
  1335. gspca_dev->usb_buf, len,
  1336. 500);
  1337. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  1338. if (ret < 0) {
  1339. err("reg_r err %d", ret);
  1340. gspca_dev->usb_err = ret;
  1341. }
  1342. }
  1343. static void reg_w1(struct gspca_dev *gspca_dev,
  1344. u16 value,
  1345. u8 data)
  1346. {
  1347. int ret;
  1348. if (gspca_dev->usb_err < 0)
  1349. return;
  1350. PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
  1351. gspca_dev->usb_buf[0] = data;
  1352. ret = usb_control_msg(gspca_dev->dev,
  1353. usb_sndctrlpipe(gspca_dev->dev, 0),
  1354. 0x08,
  1355. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1356. value,
  1357. 0,
  1358. gspca_dev->usb_buf, 1,
  1359. 500);
  1360. if (ret < 0) {
  1361. err("reg_w1 err %d", ret);
  1362. gspca_dev->usb_err = ret;
  1363. }
  1364. }
  1365. static void reg_w(struct gspca_dev *gspca_dev,
  1366. u16 value,
  1367. const u8 *buffer,
  1368. int len)
  1369. {
  1370. int ret;
  1371. if (gspca_dev->usb_err < 0)
  1372. return;
  1373. PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
  1374. value, buffer[0], buffer[1]);
  1375. #ifdef GSPCA_DEBUG
  1376. if (len > USB_BUF_SZ) {
  1377. err("reg_w: buffer overflow");
  1378. return;
  1379. }
  1380. #endif
  1381. memcpy(gspca_dev->usb_buf, buffer, len);
  1382. ret = usb_control_msg(gspca_dev->dev,
  1383. usb_sndctrlpipe(gspca_dev->dev, 0),
  1384. 0x08,
  1385. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1386. value, 0,
  1387. gspca_dev->usb_buf, len,
  1388. 500);
  1389. if (ret < 0) {
  1390. err("reg_w err %d", ret);
  1391. gspca_dev->usb_err = ret;
  1392. }
  1393. }
  1394. /* I2C write 1 byte */
  1395. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1396. {
  1397. struct sd *sd = (struct sd *) gspca_dev;
  1398. int ret;
  1399. if (gspca_dev->usb_err < 0)
  1400. return;
  1401. PDEBUG(D_USBO, "i2c_w1 [%02x] = %02x", reg, val);
  1402. switch (sd->sensor) {
  1403. case SENSOR_ADCM1700:
  1404. case SENSOR_OM6802:
  1405. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1406. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1407. break;
  1408. default: /* i2c command = a1 (400 kHz) */
  1409. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1410. break;
  1411. }
  1412. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1413. gspca_dev->usb_buf[2] = reg;
  1414. gspca_dev->usb_buf[3] = val;
  1415. gspca_dev->usb_buf[4] = 0;
  1416. gspca_dev->usb_buf[5] = 0;
  1417. gspca_dev->usb_buf[6] = 0;
  1418. gspca_dev->usb_buf[7] = 0x10;
  1419. ret = usb_control_msg(gspca_dev->dev,
  1420. usb_sndctrlpipe(gspca_dev->dev, 0),
  1421. 0x08,
  1422. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1423. 0x08, /* value = i2c */
  1424. 0,
  1425. gspca_dev->usb_buf, 8,
  1426. 500);
  1427. if (ret < 0) {
  1428. err("i2c_w1 err %d", ret);
  1429. gspca_dev->usb_err = ret;
  1430. }
  1431. }
  1432. /* I2C write 8 bytes */
  1433. static void i2c_w8(struct gspca_dev *gspca_dev,
  1434. const u8 *buffer)
  1435. {
  1436. int ret;
  1437. if (gspca_dev->usb_err < 0)
  1438. return;
  1439. PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
  1440. buffer[2], buffer[3]);
  1441. memcpy(gspca_dev->usb_buf, buffer, 8);
  1442. ret = usb_control_msg(gspca_dev->dev,
  1443. usb_sndctrlpipe(gspca_dev->dev, 0),
  1444. 0x08,
  1445. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1446. 0x08, 0, /* value, index */
  1447. gspca_dev->usb_buf, 8,
  1448. 500);
  1449. msleep(2);
  1450. if (ret < 0) {
  1451. err("i2c_w8 err %d", ret);
  1452. gspca_dev->usb_err = ret;
  1453. }
  1454. }
  1455. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1456. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1457. {
  1458. struct sd *sd = (struct sd *) gspca_dev;
  1459. u8 mode[8];
  1460. switch (sd->sensor) {
  1461. case SENSOR_ADCM1700:
  1462. case SENSOR_OM6802:
  1463. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1464. mode[0] = 0x80 | 0x10;
  1465. break;
  1466. default: /* i2c command = 91 (400 kHz) */
  1467. mode[0] = 0x81 | 0x10;
  1468. break;
  1469. }
  1470. mode[1] = sd->i2c_addr;
  1471. mode[2] = reg;
  1472. mode[3] = 0;
  1473. mode[4] = 0;
  1474. mode[5] = 0;
  1475. mode[6] = 0;
  1476. mode[7] = 0x10;
  1477. i2c_w8(gspca_dev, mode);
  1478. msleep(2);
  1479. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1480. mode[2] = 0;
  1481. i2c_w8(gspca_dev, mode);
  1482. msleep(2);
  1483. reg_r(gspca_dev, 0x0a, 5);
  1484. }
  1485. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1486. const u8 (*data)[8])
  1487. {
  1488. while ((*data)[0] != 0) {
  1489. if ((*data)[0] != DELAY)
  1490. i2c_w8(gspca_dev, *data);
  1491. else
  1492. msleep((*data)[1]);
  1493. data++;
  1494. }
  1495. }
  1496. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1497. {
  1498. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1499. msleep(10);
  1500. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1501. msleep(10);
  1502. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1503. if (gspca_dev->usb_buf[0] == 0x02
  1504. && gspca_dev->usb_buf[1] == 0x09
  1505. && gspca_dev->usb_buf[2] == 0x01
  1506. && gspca_dev->usb_buf[3] == 0x00
  1507. && gspca_dev->usb_buf[4] == 0x00) {
  1508. PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
  1509. return;
  1510. }
  1511. PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
  1512. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1513. gspca_dev->usb_buf[2]);
  1514. }
  1515. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1516. {
  1517. struct sd *sd = (struct sd *) gspca_dev;
  1518. int i, j;
  1519. u16 val = 0;
  1520. static const u8 probe_tb[][4][8] = {
  1521. { /* mi0360 */
  1522. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1523. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1524. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1525. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1526. },
  1527. { /* mt9v111 */
  1528. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1529. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1530. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1531. {}
  1532. },
  1533. };
  1534. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1535. reg_w1(gspca_dev, 0x17, 0x62);
  1536. reg_w1(gspca_dev, 0x01, 0x08);
  1537. for (j = 0; j < 3; j++)
  1538. i2c_w8(gspca_dev, probe_tb[i][j]);
  1539. msleep(2);
  1540. reg_r(gspca_dev, 0x0a, 5);
  1541. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1542. if (probe_tb[i][3][0] != 0)
  1543. i2c_w8(gspca_dev, probe_tb[i][3]);
  1544. reg_w1(gspca_dev, 0x01, 0x29);
  1545. reg_w1(gspca_dev, 0x17, 0x42);
  1546. if (val != 0xffff)
  1547. break;
  1548. }
  1549. if (gspca_dev->usb_err < 0)
  1550. return;
  1551. switch (val) {
  1552. case 0x8221:
  1553. PDEBUG(D_PROBE, "Sensor mi0360b");
  1554. sd->sensor = SENSOR_MI0360B;
  1555. break;
  1556. case 0x823a:
  1557. PDEBUG(D_PROBE, "Sensor mt9v111");
  1558. sd->sensor = SENSOR_MT9V111;
  1559. break;
  1560. case 0x8243:
  1561. PDEBUG(D_PROBE, "Sensor mi0360");
  1562. break;
  1563. default:
  1564. PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
  1565. break;
  1566. }
  1567. }
  1568. static void ov7630_probe(struct gspca_dev *gspca_dev)
  1569. {
  1570. struct sd *sd = (struct sd *) gspca_dev;
  1571. u16 val;
  1572. /* check ov76xx */
  1573. reg_w1(gspca_dev, 0x17, 0x62);
  1574. reg_w1(gspca_dev, 0x01, 0x08);
  1575. sd->i2c_addr = 0x21;
  1576. i2c_r(gspca_dev, 0x0a, 2);
  1577. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1578. reg_w1(gspca_dev, 0x01, 0x29);
  1579. reg_w1(gspca_dev, 0x17, 0x42);
  1580. if (gspca_dev->usb_err < 0)
  1581. return;
  1582. if (val == 0x7628) { /* soi768 */
  1583. sd->sensor = SENSOR_SOI768;
  1584. /*fixme: only valid for 0c45:613e?*/
  1585. gspca_dev->cam.input_flags =
  1586. V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  1587. PDEBUG(D_PROBE, "Sensor soi768");
  1588. return;
  1589. }
  1590. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1591. }
  1592. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1593. {
  1594. struct sd *sd = (struct sd *) gspca_dev;
  1595. u16 val;
  1596. /* check ov76xx */
  1597. reg_w1(gspca_dev, 0x17, 0x62);
  1598. reg_w1(gspca_dev, 0x01, 0x08);
  1599. sd->i2c_addr = 0x21;
  1600. i2c_r(gspca_dev, 0x0a, 2);
  1601. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1602. reg_w1(gspca_dev, 0x01, 0x29);
  1603. reg_w1(gspca_dev, 0x17, 0x42);
  1604. if ((val & 0xff00) == 0x7600) { /* ov76xx */
  1605. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1606. return;
  1607. }
  1608. /* check po1030 */
  1609. reg_w1(gspca_dev, 0x17, 0x62);
  1610. reg_w1(gspca_dev, 0x01, 0x08);
  1611. sd->i2c_addr = 0x6e;
  1612. i2c_r(gspca_dev, 0x00, 2);
  1613. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1614. reg_w1(gspca_dev, 0x01, 0x29);
  1615. reg_w1(gspca_dev, 0x17, 0x42);
  1616. if (gspca_dev->usb_err < 0)
  1617. return;
  1618. if (val == 0x1030) { /* po1030 */
  1619. PDEBUG(D_PROBE, "Sensor po1030");
  1620. sd->sensor = SENSOR_PO1030;
  1621. return;
  1622. }
  1623. err("Unknown sensor %04x", val);
  1624. }
  1625. /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
  1626. static void po2030n_probe(struct gspca_dev *gspca_dev)
  1627. {
  1628. struct sd *sd = (struct sd *) gspca_dev;
  1629. u16 val;
  1630. /* check gc0307 */
  1631. reg_w1(gspca_dev, 0x17, 0x62);
  1632. reg_w1(gspca_dev, 0x01, 0x08);
  1633. reg_w1(gspca_dev, 0x02, 0x22);
  1634. sd->i2c_addr = 0x21;
  1635. i2c_r(gspca_dev, 0x00, 1);
  1636. val = gspca_dev->usb_buf[4];
  1637. reg_w1(gspca_dev, 0x01, 0x29); /* reset */
  1638. reg_w1(gspca_dev, 0x17, 0x42);
  1639. if (val == 0x99) { /* gc0307 (?) */
  1640. PDEBUG(D_PROBE, "Sensor gc0307");
  1641. sd->sensor = SENSOR_GC0307;
  1642. return;
  1643. }
  1644. /* check po2030n */
  1645. reg_w1(gspca_dev, 0x17, 0x62);
  1646. reg_w1(gspca_dev, 0x01, 0x0a);
  1647. sd->i2c_addr = 0x6e;
  1648. i2c_r(gspca_dev, 0x00, 2);
  1649. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1650. reg_w1(gspca_dev, 0x01, 0x29);
  1651. reg_w1(gspca_dev, 0x17, 0x42);
  1652. if (gspca_dev->usb_err < 0)
  1653. return;
  1654. if (val == 0x2030) {
  1655. PDEBUG(D_PROBE, "Sensor po2030n");
  1656. /* sd->sensor = SENSOR_PO2030N; */
  1657. } else {
  1658. err("Unknown sensor ID %04x", val);
  1659. }
  1660. }
  1661. static void bridge_init(struct gspca_dev *gspca_dev,
  1662. const u8 *sn9c1xx)
  1663. {
  1664. struct sd *sd = (struct sd *) gspca_dev;
  1665. u8 reg0102[2];
  1666. const u8 *reg9a;
  1667. static const u8 reg9a_def[] =
  1668. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  1669. static const u8 reg9a_spec[] =
  1670. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  1671. static const u8 regd4[] = {0x60, 0x00, 0x00};
  1672. /* sensor clock already enabled in sd_init */
  1673. /* reg_w1(gspca_dev, 0xf1, 0x00); */
  1674. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1675. /* configure gpio */
  1676. reg0102[0] = sn9c1xx[1];
  1677. reg0102[1] = sn9c1xx[2];
  1678. if (gspca_dev->audio)
  1679. reg0102[1] |= 0x04; /* keep the audio connection */
  1680. reg_w(gspca_dev, 0x01, reg0102, 2);
  1681. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  1682. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  1683. switch (sd->sensor) {
  1684. case SENSOR_GC0307:
  1685. case SENSOR_OV7660:
  1686. case SENSOR_PO1030:
  1687. case SENSOR_PO2030N:
  1688. case SENSOR_SOI768:
  1689. case SENSOR_SP80708:
  1690. reg9a = reg9a_spec;
  1691. break;
  1692. default:
  1693. reg9a = reg9a_def;
  1694. break;
  1695. }
  1696. reg_w(gspca_dev, 0x9a, reg9a, 6);
  1697. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  1698. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  1699. switch (sd->sensor) {
  1700. case SENSOR_ADCM1700:
  1701. reg_w1(gspca_dev, 0x01, 0x43);
  1702. reg_w1(gspca_dev, 0x17, 0x62);
  1703. reg_w1(gspca_dev, 0x01, 0x42);
  1704. reg_w1(gspca_dev, 0x01, 0x42);
  1705. break;
  1706. case SENSOR_GC0307:
  1707. msleep(50);
  1708. reg_w1(gspca_dev, 0x01, 0x61);
  1709. reg_w1(gspca_dev, 0x17, 0x22);
  1710. reg_w1(gspca_dev, 0x01, 0x60);
  1711. reg_w1(gspca_dev, 0x01, 0x40);
  1712. msleep(50);
  1713. break;
  1714. case SENSOR_MI0360B:
  1715. reg_w1(gspca_dev, 0x01, 0x61);
  1716. reg_w1(gspca_dev, 0x17, 0x60);
  1717. reg_w1(gspca_dev, 0x01, 0x60);
  1718. reg_w1(gspca_dev, 0x01, 0x40);
  1719. break;
  1720. case SENSOR_MT9V111:
  1721. reg_w1(gspca_dev, 0x01, 0x61);
  1722. reg_w1(gspca_dev, 0x17, 0x61);
  1723. reg_w1(gspca_dev, 0x01, 0x60);
  1724. reg_w1(gspca_dev, 0x01, 0x40);
  1725. break;
  1726. case SENSOR_OM6802:
  1727. msleep(10);
  1728. reg_w1(gspca_dev, 0x02, 0x73);
  1729. reg_w1(gspca_dev, 0x17, 0x60);
  1730. reg_w1(gspca_dev, 0x01, 0x22);
  1731. msleep(100);
  1732. reg_w1(gspca_dev, 0x01, 0x62);
  1733. reg_w1(gspca_dev, 0x17, 0x64);
  1734. reg_w1(gspca_dev, 0x17, 0x64);
  1735. reg_w1(gspca_dev, 0x01, 0x42);
  1736. msleep(10);
  1737. reg_w1(gspca_dev, 0x01, 0x42);
  1738. i2c_w8(gspca_dev, om6802_init0[0]);
  1739. i2c_w8(gspca_dev, om6802_init0[1]);
  1740. msleep(15);
  1741. reg_w1(gspca_dev, 0x02, 0x71);
  1742. msleep(150);
  1743. break;
  1744. case SENSOR_OV7630:
  1745. reg_w1(gspca_dev, 0x01, 0x61);
  1746. reg_w1(gspca_dev, 0x17, 0xe2);
  1747. reg_w1(gspca_dev, 0x01, 0x60);
  1748. reg_w1(gspca_dev, 0x01, 0x40);
  1749. break;
  1750. case SENSOR_OV7648:
  1751. reg_w1(gspca_dev, 0x01, 0x63);
  1752. reg_w1(gspca_dev, 0x17, 0x20);
  1753. reg_w1(gspca_dev, 0x01, 0x62);
  1754. reg_w1(gspca_dev, 0x01, 0x42);
  1755. break;
  1756. case SENSOR_PO1030:
  1757. case SENSOR_SOI768:
  1758. reg_w1(gspca_dev, 0x01, 0x61);
  1759. reg_w1(gspca_dev, 0x17, 0x20);
  1760. reg_w1(gspca_dev, 0x01, 0x60);
  1761. reg_w1(gspca_dev, 0x01, 0x40);
  1762. break;
  1763. case SENSOR_PO2030N:
  1764. case SENSOR_OV7660:
  1765. reg_w1(gspca_dev, 0x01, 0x63);
  1766. reg_w1(gspca_dev, 0x17, 0x20);
  1767. reg_w1(gspca_dev, 0x01, 0x62);
  1768. reg_w1(gspca_dev, 0x01, 0x42);
  1769. break;
  1770. case SENSOR_SP80708:
  1771. reg_w1(gspca_dev, 0x01, 0x63);
  1772. reg_w1(gspca_dev, 0x17, 0x20);
  1773. reg_w1(gspca_dev, 0x01, 0x62);
  1774. reg_w1(gspca_dev, 0x01, 0x42);
  1775. msleep(100);
  1776. reg_w1(gspca_dev, 0x02, 0x62);
  1777. break;
  1778. default:
  1779. /* case SENSOR_HV7131R: */
  1780. /* case SENSOR_MI0360: */
  1781. /* case SENSOR_MO4000: */
  1782. reg_w1(gspca_dev, 0x01, 0x43);
  1783. reg_w1(gspca_dev, 0x17, 0x61);
  1784. reg_w1(gspca_dev, 0x01, 0x42);
  1785. if (sd->sensor == SENSOR_HV7131R)
  1786. hv7131r_probe(gspca_dev);
  1787. break;
  1788. }
  1789. }
  1790. /* this function is called at probe time */
  1791. static int sd_config(struct gspca_dev *gspca_dev,
  1792. const struct usb_device_id *id)
  1793. {
  1794. struct sd *sd = (struct sd *) gspca_dev;
  1795. struct cam *cam;
  1796. sd->bridge = id->driver_info >> 16;
  1797. sd->sensor = id->driver_info;
  1798. cam = &gspca_dev->cam;
  1799. if (sd->sensor == SENSOR_ADCM1700) {
  1800. cam->cam_mode = cif_mode;
  1801. cam->nmodes = ARRAY_SIZE(cif_mode);
  1802. } else {
  1803. cam->cam_mode = vga_mode;
  1804. cam->nmodes = ARRAY_SIZE(vga_mode);
  1805. }
  1806. cam->npkt = 24; /* 24 packets per ISOC message */
  1807. cam->ctrls = sd->ctrls;
  1808. sd->ag_cnt = -1;
  1809. sd->quality = QUALITY_DEF;
  1810. sd->jpegqual = 80;
  1811. return 0;
  1812. }
  1813. /* this function is called at probe and resume time */
  1814. static int sd_init(struct gspca_dev *gspca_dev)
  1815. {
  1816. struct sd *sd = (struct sd *) gspca_dev;
  1817. const u8 *sn9c1xx;
  1818. u8 regGpio[] = { 0x29, 0x74 }; /* with audio */
  1819. u8 regF1;
  1820. /* setup a selector by bridge */
  1821. reg_w1(gspca_dev, 0xf1, 0x01);
  1822. reg_r(gspca_dev, 0x00, 1);
  1823. reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
  1824. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1825. regF1 = gspca_dev->usb_buf[0];
  1826. if (gspca_dev->usb_err < 0)
  1827. return gspca_dev->usb_err;
  1828. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  1829. switch (sd->bridge) {
  1830. case BRIDGE_SN9C102P:
  1831. if (regF1 != 0x11)
  1832. return -ENODEV;
  1833. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1834. break;
  1835. case BRIDGE_SN9C105:
  1836. if (regF1 != 0x11)
  1837. return -ENODEV;
  1838. if (sd->sensor == SENSOR_MI0360)
  1839. mi0360_probe(gspca_dev);
  1840. reg_w(gspca_dev, 0x01, regGpio, 2);
  1841. break;
  1842. case BRIDGE_SN9C120:
  1843. if (regF1 != 0x12)
  1844. return -ENODEV;
  1845. switch (sd->sensor) {
  1846. case SENSOR_MI0360:
  1847. mi0360_probe(gspca_dev);
  1848. break;
  1849. case SENSOR_OV7630:
  1850. ov7630_probe(gspca_dev);
  1851. break;
  1852. case SENSOR_OV7648:
  1853. ov7648_probe(gspca_dev);
  1854. break;
  1855. case SENSOR_PO2030N:
  1856. po2030n_probe(gspca_dev);
  1857. break;
  1858. }
  1859. regGpio[1] = 0x70; /* no audio */
  1860. reg_w(gspca_dev, 0x01, regGpio, 2);
  1861. break;
  1862. default:
  1863. /* case BRIDGE_SN9C110: */
  1864. /* case BRIDGE_SN9C325: */
  1865. if (regF1 != 0x12)
  1866. return -ENODEV;
  1867. reg_w1(gspca_dev, 0x02, 0x62);
  1868. break;
  1869. }
  1870. if (sd->sensor == SENSOR_OM6802)
  1871. sd->ctrls[SHARPNESS].def = 0x10;
  1872. /* Note we do not disable the sensor clock here (power saving mode),
  1873. as that also disables the button on the cam. */
  1874. reg_w1(gspca_dev, 0xf1, 0x00);
  1875. /* set the i2c address */
  1876. sn9c1xx = sn_tb[sd->sensor];
  1877. sd->i2c_addr = sn9c1xx[9];
  1878. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  1879. return gspca_dev->usb_err;
  1880. }
  1881. static u32 setexposure(struct gspca_dev *gspca_dev,
  1882. u32 expo)
  1883. {
  1884. struct sd *sd = (struct sd *) gspca_dev;
  1885. switch (sd->sensor) {
  1886. case SENSOR_GC0307: {
  1887. int a, b;
  1888. /* expo = 0..255 -> a = 19..43 */
  1889. a = 19 + expo * 25 / 256;
  1890. i2c_w1(gspca_dev, 0x68, a);
  1891. a -= 12;
  1892. b = a * a * 4; /* heuristic */
  1893. i2c_w1(gspca_dev, 0x03, b >> 8);
  1894. i2c_w1(gspca_dev, 0x04, b);
  1895. break;
  1896. }
  1897. case SENSOR_HV7131R: {
  1898. u8 Expodoit[] =
  1899. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1900. Expodoit[3] = expo >> 16;
  1901. Expodoit[4] = expo >> 8;
  1902. Expodoit[5] = expo;
  1903. i2c_w8(gspca_dev, Expodoit);
  1904. break;
  1905. }
  1906. case SENSOR_MI0360:
  1907. case SENSOR_MI0360B: {
  1908. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1909. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1910. static const u8 doit[] = /* update sensor */
  1911. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1912. static const u8 sensorgo[] = /* sensor on */
  1913. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1914. if (expo > 0x0635)
  1915. expo = 0x0635;
  1916. else if (expo < 0x0001)
  1917. expo = 0x0001;
  1918. expoMi[3] = expo >> 8;
  1919. expoMi[4] = expo;
  1920. i2c_w8(gspca_dev, expoMi);
  1921. i2c_w8(gspca_dev, doit);
  1922. i2c_w8(gspca_dev, sensorgo);
  1923. break;
  1924. }
  1925. case SENSOR_MO4000: {
  1926. u8 expoMof[] =
  1927. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1928. u8 expoMo10[] =
  1929. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1930. static const u8 gainMo[] =
  1931. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1932. if (expo > 0x1fff)
  1933. expo = 0x1fff;
  1934. else if (expo < 0x0001)
  1935. expo = 0x0001;
  1936. expoMof[3] = (expo & 0x03fc) >> 2;
  1937. i2c_w8(gspca_dev, expoMof);
  1938. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1939. | ((expo & 0x0003) << 4);
  1940. i2c_w8(gspca_dev, expoMo10);
  1941. i2c_w8(gspca_dev, gainMo);
  1942. PDEBUG(D_FRAM, "set exposure %d",
  1943. ((expoMo10[3] & 0x07) << 10)
  1944. | (expoMof[3] << 2)
  1945. | ((expoMo10[3] & 0x30) >> 4));
  1946. break;
  1947. }
  1948. case SENSOR_MT9V111: {
  1949. u8 expo_c1[] =
  1950. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1951. if (expo > 0x0280)
  1952. expo = 0x0280;
  1953. else if (expo < 0x0040)
  1954. expo = 0x0040;
  1955. expo_c1[3] = expo >> 8;
  1956. expo_c1[4] = expo;
  1957. i2c_w8(gspca_dev, expo_c1);
  1958. break;
  1959. }
  1960. case SENSOR_OM6802: {
  1961. u8 gainOm[] =
  1962. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1963. /* preset AGC - works when AutoExpo = off */
  1964. if (expo > 0x03ff)
  1965. expo = 0x03ff;
  1966. if (expo < 0x0001)
  1967. expo = 0x0001;
  1968. gainOm[3] = expo >> 2;
  1969. i2c_w8(gspca_dev, gainOm);
  1970. reg_w1(gspca_dev, 0x96, expo >> 5);
  1971. PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
  1972. break;
  1973. }
  1974. }
  1975. return expo;
  1976. }
  1977. static void setbrightness(struct gspca_dev *gspca_dev)
  1978. {
  1979. struct sd *sd = (struct sd *) gspca_dev;
  1980. unsigned int expo;
  1981. int brightness;
  1982. u8 k2;
  1983. brightness = sd->ctrls[BRIGHTNESS].val;
  1984. k2 = (brightness - 0x80) >> 2;
  1985. switch (sd->sensor) {
  1986. case SENSOR_ADCM1700:
  1987. if (k2 > 0x1f)
  1988. k2 = 0; /* only positive Y offset */
  1989. break;
  1990. case SENSOR_HV7131R:
  1991. expo = brightness << 12;
  1992. if (expo > 0x002dc6c0)
  1993. expo = 0x002dc6c0;
  1994. else if (expo < 0x02a0)
  1995. expo = 0x02a0;
  1996. sd->exposure = setexposure(gspca_dev, expo);
  1997. break;
  1998. case SENSOR_MI0360:
  1999. case SENSOR_MO4000:
  2000. expo = brightness << 4;
  2001. sd->exposure = setexposure(gspca_dev, expo);
  2002. break;
  2003. case SENSOR_MI0360B:
  2004. expo = brightness << 2;
  2005. sd->exposure = setexposure(gspca_dev, expo);
  2006. break;
  2007. case SENSOR_GC0307:
  2008. case SENSOR_MT9V111:
  2009. expo = brightness;
  2010. sd->exposure = setexposure(gspca_dev, expo);
  2011. return; /* don't set the Y offset */
  2012. case SENSOR_OM6802:
  2013. expo = brightness << 2;
  2014. sd->exposure = setexposure(gspca_dev, expo);
  2015. k2 = brightness >> 3;
  2016. break;
  2017. }
  2018. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  2019. }
  2020. static void setcontrast(struct gspca_dev *gspca_dev)
  2021. {
  2022. struct sd *sd = (struct sd *) gspca_dev;
  2023. u8 k2;
  2024. u8 contrast[6];
  2025. k2 = sd->ctrls[CONTRAST].val * 0x30 / (CONTRAST_MAX + 1)
  2026. + 0x10; /* 10..40 */
  2027. contrast[0] = (k2 + 1) / 2; /* red */
  2028. contrast[1] = 0;
  2029. contrast[2] = k2; /* green */
  2030. contrast[3] = 0;
  2031. contrast[4] = (k2 + 1) / 5; /* blue */
  2032. contrast[5] = 0;
  2033. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  2034. }
  2035. static void setcolors(struct gspca_dev *gspca_dev)
  2036. {
  2037. struct sd *sd = (struct sd *) gspca_dev;
  2038. int i, v, colors;
  2039. const s16 *uv;
  2040. u8 reg8a[12]; /* U & V gains */
  2041. static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
  2042. -24, -38, 64, /* UR UG UB */
  2043. 62, -51, -9 /* VR VG VB */
  2044. };
  2045. static const s16 uv_mi0360b[6] = {
  2046. -20, -38, 64, /* UR UG UB */
  2047. 60, -51, -9 /* VR VG VB */
  2048. };
  2049. colors = sd->ctrls[COLORS].val;
  2050. if (sd->sensor == SENSOR_MI0360B)
  2051. uv = uv_mi0360b;
  2052. else
  2053. uv = uv_com;
  2054. for (i = 0; i < 6; i++) {
  2055. v = uv[i] * colors / COLORS_DEF;
  2056. reg8a[i * 2] = v;
  2057. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  2058. }
  2059. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  2060. }
  2061. static void setredblue(struct gspca_dev *gspca_dev)
  2062. {
  2063. struct sd *sd = (struct sd *) gspca_dev;
  2064. reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val);
  2065. /* reg_w1(gspca_dev, 0x07, 32); */
  2066. reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val);
  2067. }
  2068. static void setgamma(struct gspca_dev *gspca_dev)
  2069. {
  2070. struct sd *sd = (struct sd *) gspca_dev;
  2071. int i, val;
  2072. u8 gamma[17];
  2073. const u8 *gamma_base;
  2074. static const u8 delta[17] = {
  2075. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  2076. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  2077. };
  2078. switch (sd->sensor) {
  2079. case SENSOR_ADCM1700:
  2080. gamma_base = gamma_spec_0;
  2081. break;
  2082. case SENSOR_HV7131R:
  2083. case SENSOR_MI0360B:
  2084. case SENSOR_MT9V111:
  2085. gamma_base = gamma_spec_1;
  2086. break;
  2087. case SENSOR_GC0307:
  2088. gamma_base = gamma_spec_2;
  2089. break;
  2090. case SENSOR_SP80708:
  2091. gamma_base = gamma_spec_3;
  2092. break;
  2093. default:
  2094. gamma_base = gamma_def;
  2095. break;
  2096. }
  2097. val = sd->ctrls[GAMMA].val;
  2098. for (i = 0; i < sizeof gamma; i++)
  2099. gamma[i] = gamma_base[i]
  2100. + delta[i] * (val - GAMMA_DEF) / 32;
  2101. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  2102. }
  2103. static void setautogain(struct gspca_dev *gspca_dev)
  2104. {
  2105. struct sd *sd = (struct sd *) gspca_dev;
  2106. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
  2107. return;
  2108. switch (sd->sensor) {
  2109. case SENSOR_OV7630:
  2110. case SENSOR_OV7648: {
  2111. u8 comb;
  2112. if (sd->sensor == SENSOR_OV7630)
  2113. comb = 0xc0;
  2114. else
  2115. comb = 0xa0;
  2116. if (sd->ctrls[AUTOGAIN].val)
  2117. comb |= 0x03;
  2118. i2c_w1(&sd->gspca_dev, 0x13, comb);
  2119. return;
  2120. }
  2121. }
  2122. if (sd->ctrls[AUTOGAIN].val)
  2123. sd->ag_cnt = AG_CNT_START;
  2124. else
  2125. sd->ag_cnt = -1;
  2126. }
  2127. static void sethvflip(struct gspca_dev *gspca_dev)
  2128. {
  2129. struct sd *sd = (struct sd *) gspca_dev;
  2130. u8 comn;
  2131. switch (sd->sensor) {
  2132. case SENSOR_HV7131R:
  2133. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  2134. if (sd->ctrls[VFLIP].val)
  2135. comn |= 0x01;
  2136. i2c_w1(gspca_dev, 0x01, comn); /* sctra */
  2137. break;
  2138. case SENSOR_OV7630:
  2139. comn = 0x02;
  2140. if (!sd->ctrls[VFLIP].val)
  2141. comn |= 0x80;
  2142. i2c_w1(gspca_dev, 0x75, comn);
  2143. break;
  2144. case SENSOR_OV7648:
  2145. comn = 0x06;
  2146. if (sd->ctrls[VFLIP].val)
  2147. comn |= 0x80;
  2148. i2c_w1(gspca_dev, 0x75, comn);
  2149. break;
  2150. case SENSOR_PO2030N:
  2151. /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
  2152. * (reset value: 0x0A)
  2153. * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
  2154. * bit6: VM: Vertical Mirror: 0: disable, 1: enable
  2155. * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
  2156. * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
  2157. * bit3-0: X
  2158. */
  2159. comn = 0x0a;
  2160. if (sd->ctrls[HFLIP].val)
  2161. comn |= 0x80;
  2162. if (sd->ctrls[VFLIP].val)
  2163. comn |= 0x40;
  2164. i2c_w1(&sd->gspca_dev, 0x1e, comn);
  2165. break;
  2166. }
  2167. }
  2168. static void setsharpness(struct gspca_dev *gspca_dev)
  2169. {
  2170. struct sd *sd = (struct sd *) gspca_dev;
  2171. reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val);
  2172. }
  2173. static void setinfrared(struct gspca_dev *gspca_dev)
  2174. {
  2175. struct sd *sd = (struct sd *) gspca_dev;
  2176. if (gspca_dev->ctrl_dis & (1 << INFRARED))
  2177. return;
  2178. /*fixme: different sequence for StarCam Clip and StarCam 370i */
  2179. /* Clip */
  2180. i2c_w1(gspca_dev, 0x02, /* gpio */
  2181. sd->ctrls[INFRARED].val ? 0x66 : 0x64);
  2182. }
  2183. static void setfreq(struct gspca_dev *gspca_dev)
  2184. {
  2185. struct sd *sd = (struct sd *) gspca_dev;
  2186. if (gspca_dev->ctrl_dis & (1 << FREQ))
  2187. return;
  2188. if (sd->sensor == SENSOR_OV7660) {
  2189. u8 com8;
  2190. com8 = 0xdf; /* auto gain/wb/expo */
  2191. switch (sd->ctrls[FREQ].val) {
  2192. case 0: /* Banding filter disabled */
  2193. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  2194. break;
  2195. case 1: /* 50 hz */
  2196. i2c_w1(gspca_dev, 0x13, com8);
  2197. i2c_w1(gspca_dev, 0x3b, 0x0a);
  2198. break;
  2199. case 2: /* 60 hz */
  2200. i2c_w1(gspca_dev, 0x13, com8);
  2201. i2c_w1(gspca_dev, 0x3b, 0x02);
  2202. break;
  2203. }
  2204. } else {
  2205. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  2206. /* Get reg2a / reg2d base values */
  2207. switch (sd->sensor) {
  2208. case SENSOR_OV7630:
  2209. reg2a = 0x08;
  2210. reg2d = 0x01;
  2211. break;
  2212. case SENSOR_OV7648:
  2213. reg2a = 0x11;
  2214. reg2d = 0x81;
  2215. break;
  2216. }
  2217. switch (sd->ctrls[FREQ].val) {
  2218. case 0: /* Banding filter disabled */
  2219. break;
  2220. case 1: /* 50 hz (filter on and framerate adj) */
  2221. reg2a |= 0x80;
  2222. reg2b = 0xac;
  2223. reg2d |= 0x04;
  2224. break;
  2225. case 2: /* 60 hz (filter on, no framerate adj) */
  2226. reg2a |= 0x80;
  2227. reg2d |= 0x04;
  2228. break;
  2229. }
  2230. i2c_w1(gspca_dev, 0x2a, reg2a);
  2231. i2c_w1(gspca_dev, 0x2b, reg2b);
  2232. i2c_w1(gspca_dev, 0x2d, reg2d);
  2233. }
  2234. }
  2235. static void setjpegqual(struct gspca_dev *gspca_dev)
  2236. {
  2237. struct sd *sd = (struct sd *) gspca_dev;
  2238. int i, sc;
  2239. if (sd->jpegqual < 50)
  2240. sc = 5000 / sd->jpegqual;
  2241. else
  2242. sc = 200 - sd->jpegqual * 2;
  2243. #if USB_BUF_SZ < 64
  2244. #error "No room enough in usb_buf for quantization table"
  2245. #endif
  2246. for (i = 0; i < 64; i++)
  2247. gspca_dev->usb_buf[i] =
  2248. (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
  2249. usb_control_msg(gspca_dev->dev,
  2250. usb_sndctrlpipe(gspca_dev->dev, 0),
  2251. 0x08,
  2252. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2253. 0x0100, 0,
  2254. gspca_dev->usb_buf, 64,
  2255. 500);
  2256. for (i = 0; i < 64; i++)
  2257. gspca_dev->usb_buf[i] =
  2258. (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
  2259. usb_control_msg(gspca_dev->dev,
  2260. usb_sndctrlpipe(gspca_dev->dev, 0),
  2261. 0x08,
  2262. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2263. 0x0140, 0,
  2264. gspca_dev->usb_buf, 64,
  2265. 500);
  2266. sd->reg18 ^= 0x40;
  2267. reg_w1(gspca_dev, 0x18, sd->reg18);
  2268. }
  2269. /* -- start the camera -- */
  2270. static int sd_start(struct gspca_dev *gspca_dev)
  2271. {
  2272. struct sd *sd = (struct sd *) gspca_dev;
  2273. int i;
  2274. u8 reg1, reg17;
  2275. const u8 *sn9c1xx;
  2276. const u8 (*init)[8];
  2277. int mode;
  2278. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  2279. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  2280. static const u8 CA_adcm1700[] =
  2281. { 0x14, 0xec, 0x0a, 0xf6 };
  2282. static const u8 CA_po2030n[] =
  2283. { 0x1e, 0xe2, 0x14, 0xec };
  2284. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  2285. static const u8 CE_gc0307[] =
  2286. { 0x32, 0xce, 0x2d, 0xd3 };
  2287. static const u8 CE_ov76xx[] =
  2288. { 0x32, 0xdd, 0x32, 0xdd };
  2289. static const u8 CE_po2030n[] =
  2290. { 0x14, 0xe7, 0x1e, 0xdd };
  2291. /* create the JPEG header */
  2292. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  2293. 0x21); /* JPEG 422 */
  2294. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2295. /* initialize the bridge */
  2296. sn9c1xx = sn_tb[sd->sensor];
  2297. bridge_init(gspca_dev, sn9c1xx);
  2298. /* initialize the sensor */
  2299. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  2300. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  2301. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  2302. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  2303. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  2304. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2305. if (sd->sensor == SENSOR_ADCM1700) {
  2306. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  2307. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  2308. } else {
  2309. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  2310. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  2311. }
  2312. reg_w1(gspca_dev, 0xc6, 0x00);
  2313. reg_w1(gspca_dev, 0xc7, 0x00);
  2314. if (sd->sensor == SENSOR_ADCM1700) {
  2315. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  2316. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  2317. } else {
  2318. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  2319. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  2320. }
  2321. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2322. switch (sd->sensor) {
  2323. case SENSOR_GC0307:
  2324. reg17 = 0xa2;
  2325. break;
  2326. case SENSOR_MT9V111:
  2327. case SENSOR_MI0360B:
  2328. reg17 = 0xe0;
  2329. break;
  2330. case SENSOR_ADCM1700:
  2331. case SENSOR_OV7630:
  2332. reg17 = 0xe2;
  2333. break;
  2334. case SENSOR_OV7648:
  2335. reg17 = 0x20;
  2336. break;
  2337. case SENSOR_OV7660:
  2338. case SENSOR_SOI768:
  2339. reg17 = 0xa0;
  2340. break;
  2341. case SENSOR_PO1030:
  2342. case SENSOR_PO2030N:
  2343. reg17 = 0xa0;
  2344. break;
  2345. default:
  2346. reg17 = 0x60;
  2347. break;
  2348. }
  2349. reg_w1(gspca_dev, 0x17, reg17);
  2350. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  2351. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  2352. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  2353. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  2354. setgamma(gspca_dev);
  2355. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  2356. for (i = 0; i < 8; i++)
  2357. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2358. switch (sd->sensor) {
  2359. case SENSOR_ADCM1700:
  2360. case SENSOR_OV7660:
  2361. case SENSOR_SP80708:
  2362. reg_w1(gspca_dev, 0x9a, 0x05);
  2363. break;
  2364. case SENSOR_GC0307:
  2365. case SENSOR_MT9V111:
  2366. case SENSOR_MI0360B:
  2367. reg_w1(gspca_dev, 0x9a, 0x07);
  2368. break;
  2369. case SENSOR_OV7630:
  2370. case SENSOR_OV7648:
  2371. reg_w1(gspca_dev, 0x9a, 0x0a);
  2372. break;
  2373. case SENSOR_PO2030N:
  2374. case SENSOR_SOI768:
  2375. reg_w1(gspca_dev, 0x9a, 0x06);
  2376. break;
  2377. default:
  2378. reg_w1(gspca_dev, 0x9a, 0x08);
  2379. break;
  2380. }
  2381. setsharpness(gspca_dev);
  2382. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2383. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  2384. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  2385. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  2386. init = NULL;
  2387. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  2388. if (mode)
  2389. reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
  2390. else
  2391. reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
  2392. reg17 = 0x61; /* 0x:20: enable sensor clock */
  2393. switch (sd->sensor) {
  2394. case SENSOR_ADCM1700:
  2395. init = adcm1700_sensor_param1;
  2396. reg1 = 0x46;
  2397. reg17 = 0xe2;
  2398. break;
  2399. case SENSOR_GC0307:
  2400. init = gc0307_sensor_param1;
  2401. reg17 = 0xa2;
  2402. reg1 = 0x44;
  2403. break;
  2404. case SENSOR_MI0360B:
  2405. init = mi0360b_sensor_param1;
  2406. reg1 &= ~0x02; /* don't inverse pin S_PWR_DN */
  2407. reg17 = 0xe2;
  2408. break;
  2409. case SENSOR_MO4000:
  2410. if (mode) {
  2411. /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
  2412. reg1 = 0x06; /* clk 24Mz */
  2413. } else {
  2414. reg17 = 0x22; /* 640 MCKSIZE */
  2415. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  2416. }
  2417. break;
  2418. case SENSOR_MT9V111:
  2419. init = mt9v111_sensor_param1;
  2420. if (mode) {
  2421. reg1 = 0x04; /* 320 clk 48Mhz */
  2422. } else {
  2423. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  2424. reg17 = 0xc2;
  2425. }
  2426. break;
  2427. case SENSOR_OM6802:
  2428. init = om6802_sensor_param1;
  2429. reg17 = 0x64; /* 640 MCKSIZE */
  2430. break;
  2431. case SENSOR_OV7630:
  2432. init = ov7630_sensor_param1;
  2433. reg17 = 0xe2;
  2434. reg1 = 0x44;
  2435. break;
  2436. case SENSOR_OV7648:
  2437. init = ov7648_sensor_param1;
  2438. reg17 = 0x21;
  2439. /* reg1 = 0x42; * 42 - 46? */
  2440. break;
  2441. case SENSOR_OV7660:
  2442. init = ov7660_sensor_param1;
  2443. if (sd->bridge == BRIDGE_SN9C120) {
  2444. if (mode) { /* 320x240 - 160x120 */
  2445. reg17 = 0xa2;
  2446. reg1 = 0x44; /* 48 Mhz, video trf eneble */
  2447. }
  2448. } else {
  2449. reg17 = 0x22;
  2450. reg1 = 0x06; /* 24 Mhz, video trf eneble
  2451. * inverse power down */
  2452. }
  2453. break;
  2454. case SENSOR_PO1030:
  2455. init = po1030_sensor_param1;
  2456. reg17 = 0xa2;
  2457. reg1 = 0x44;
  2458. break;
  2459. case SENSOR_PO2030N:
  2460. init = po2030n_sensor_param1;
  2461. reg1 = 0x46;
  2462. reg17 = 0xa2;
  2463. break;
  2464. case SENSOR_SOI768:
  2465. init = soi768_sensor_param1;
  2466. reg1 = 0x44;
  2467. reg17 = 0xa2;
  2468. break;
  2469. case SENSOR_SP80708:
  2470. init = sp80708_sensor_param1;
  2471. if (mode) {
  2472. /*?? reg1 = 0x04; * 320 clk 48Mhz */
  2473. } else {
  2474. reg1 = 0x46; /* 640 clk 48Mz */
  2475. reg17 = 0xa2;
  2476. }
  2477. break;
  2478. }
  2479. /* more sensor initialization - param1 */
  2480. if (init != NULL) {
  2481. i2c_w_seq(gspca_dev, init);
  2482. /* init = NULL; */
  2483. }
  2484. reg_w(gspca_dev, 0xc0, C0, 6);
  2485. switch (sd->sensor) {
  2486. case SENSOR_ADCM1700:
  2487. case SENSOR_GC0307:
  2488. case SENSOR_SOI768:
  2489. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2490. break;
  2491. case SENSOR_PO2030N:
  2492. reg_w(gspca_dev, 0xca, CA_po2030n, 4);
  2493. break;
  2494. default:
  2495. reg_w(gspca_dev, 0xca, CA, 4);
  2496. break;
  2497. }
  2498. switch (sd->sensor) {
  2499. case SENSOR_ADCM1700:
  2500. case SENSOR_OV7630:
  2501. case SENSOR_OV7648:
  2502. case SENSOR_OV7660:
  2503. case SENSOR_SOI768:
  2504. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2505. break;
  2506. case SENSOR_GC0307:
  2507. reg_w(gspca_dev, 0xce, CE_gc0307, 4);
  2508. break;
  2509. case SENSOR_PO2030N:
  2510. reg_w(gspca_dev, 0xce, CE_po2030n, 4);
  2511. break;
  2512. default:
  2513. reg_w(gspca_dev, 0xce, CE, 4);
  2514. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2515. break;
  2516. }
  2517. /* here change size mode 0 -> VGA; 1 -> CIF */
  2518. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2519. reg_w1(gspca_dev, 0x18, sd->reg18);
  2520. setjpegqual(gspca_dev);
  2521. reg_w1(gspca_dev, 0x17, reg17);
  2522. reg_w1(gspca_dev, 0x01, reg1);
  2523. sethvflip(gspca_dev);
  2524. setbrightness(gspca_dev);
  2525. setcontrast(gspca_dev);
  2526. setcolors(gspca_dev);
  2527. setautogain(gspca_dev);
  2528. setfreq(gspca_dev);
  2529. return gspca_dev->usb_err;
  2530. }
  2531. static void sd_stopN(struct gspca_dev *gspca_dev)
  2532. {
  2533. struct sd *sd = (struct sd *) gspca_dev;
  2534. static const u8 stophv7131[] =
  2535. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2536. static const u8 stopmi0360[] =
  2537. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2538. static const u8 stopov7648[] =
  2539. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2540. static const u8 stopsoi768[] =
  2541. { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
  2542. u8 data;
  2543. const u8 *sn9c1xx;
  2544. data = 0x0b;
  2545. switch (sd->sensor) {
  2546. case SENSOR_GC0307:
  2547. data = 0x29;
  2548. break;
  2549. case SENSOR_HV7131R:
  2550. i2c_w8(gspca_dev, stophv7131);
  2551. data = 0x2b;
  2552. break;
  2553. case SENSOR_MI0360:
  2554. case SENSOR_MI0360B:
  2555. i2c_w8(gspca_dev, stopmi0360);
  2556. data = 0x29;
  2557. break;
  2558. case SENSOR_OV7648:
  2559. i2c_w8(gspca_dev, stopov7648);
  2560. /* fall thru */
  2561. case SENSOR_MT9V111:
  2562. case SENSOR_OV7630:
  2563. case SENSOR_PO1030:
  2564. data = 0x29;
  2565. break;
  2566. case SENSOR_SOI768:
  2567. i2c_w8(gspca_dev, stopsoi768);
  2568. data = 0x29;
  2569. break;
  2570. }
  2571. sn9c1xx = sn_tb[sd->sensor];
  2572. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2573. reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
  2574. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2575. reg_w1(gspca_dev, 0x01, data);
  2576. /* Don't disable sensor clock as that disables the button on the cam */
  2577. /* reg_w1(gspca_dev, 0xf1, 0x01); */
  2578. }
  2579. static void do_autogain(struct gspca_dev *gspca_dev)
  2580. {
  2581. struct sd *sd = (struct sd *) gspca_dev;
  2582. int delta;
  2583. int expotimes;
  2584. u8 luma_mean = 130;
  2585. u8 luma_delta = 20;
  2586. /* Thanks S., without your advice, autobright should not work :) */
  2587. if (sd->ag_cnt < 0)
  2588. return;
  2589. if (--sd->ag_cnt >= 0)
  2590. return;
  2591. sd->ag_cnt = AG_CNT_START;
  2592. delta = atomic_read(&sd->avg_lum);
  2593. PDEBUG(D_FRAM, "mean lum %d", delta);
  2594. if (delta < luma_mean - luma_delta ||
  2595. delta > luma_mean + luma_delta) {
  2596. switch (sd->sensor) {
  2597. case SENSOR_GC0307:
  2598. expotimes = sd->exposure;
  2599. expotimes += (luma_mean - delta) >> 6;
  2600. if (expotimes < 0)
  2601. expotimes = 0;
  2602. sd->exposure = setexposure(gspca_dev,
  2603. (unsigned int) expotimes);
  2604. break;
  2605. case SENSOR_HV7131R:
  2606. expotimes = sd->exposure >> 8;
  2607. expotimes += (luma_mean - delta) >> 4;
  2608. if (expotimes < 0)
  2609. expotimes = 0;
  2610. sd->exposure = setexposure(gspca_dev,
  2611. (unsigned int) (expotimes << 8));
  2612. break;
  2613. case SENSOR_OM6802:
  2614. expotimes = sd->exposure;
  2615. expotimes += (luma_mean - delta) >> 2;
  2616. if (expotimes < 0)
  2617. expotimes = 0;
  2618. sd->exposure = setexposure(gspca_dev,
  2619. (unsigned int) expotimes);
  2620. setredblue(gspca_dev);
  2621. break;
  2622. default:
  2623. /* case SENSOR_MO4000: */
  2624. /* case SENSOR_MI0360: */
  2625. /* case SENSOR_MI0360B: */
  2626. /* case SENSOR_MT9V111: */
  2627. expotimes = sd->exposure;
  2628. expotimes += (luma_mean - delta) >> 6;
  2629. if (expotimes < 0)
  2630. expotimes = 0;
  2631. sd->exposure = setexposure(gspca_dev,
  2632. (unsigned int) expotimes);
  2633. setredblue(gspca_dev);
  2634. break;
  2635. }
  2636. }
  2637. }
  2638. /* scan the URB packets */
  2639. /* This function is run at interrupt level. */
  2640. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2641. u8 *data, /* isoc packet */
  2642. int len) /* iso packet length */
  2643. {
  2644. struct sd *sd = (struct sd *) gspca_dev;
  2645. int sof, avg_lum;
  2646. /* the image ends on a 64 bytes block starting with
  2647. * ff d9 ff ff 00 c4 c4 96
  2648. * and followed by various information including luminosity */
  2649. /* this block may be splitted between two packets */
  2650. /* a new image always starts in a new packet */
  2651. switch (gspca_dev->last_packet_type) {
  2652. case DISCARD_PACKET: /* restart image building */
  2653. sof = len - 64;
  2654. if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9)
  2655. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  2656. return;
  2657. case LAST_PACKET: /* put the JPEG 422 header */
  2658. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2659. sd->jpeg_hdr, JPEG_HDR_SZ);
  2660. break;
  2661. }
  2662. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2663. data = gspca_dev->image;
  2664. if (data == NULL)
  2665. return;
  2666. sof = gspca_dev->image_len - 64;
  2667. if (data[sof] != 0xff
  2668. || data[sof + 1] != 0xd9)
  2669. return;
  2670. /* end of image found - remove the trailing data */
  2671. gspca_dev->image_len = sof + 2;
  2672. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  2673. if (sd->ag_cnt < 0)
  2674. return;
  2675. /* w1 w2 w3 */
  2676. /* w4 w5 w6 */
  2677. /* w7 w8 */
  2678. /* w4 */
  2679. avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
  2680. /* w6 */
  2681. avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
  2682. /* w2 */
  2683. avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
  2684. /* w8 */
  2685. avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
  2686. /* w5 */
  2687. avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
  2688. avg_lum >>= 4;
  2689. atomic_set(&sd->avg_lum, avg_lum);
  2690. }
  2691. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  2692. struct v4l2_jpegcompression *jcomp)
  2693. {
  2694. struct sd *sd = (struct sd *) gspca_dev;
  2695. if (jcomp->quality < QUALITY_MIN)
  2696. sd->quality = QUALITY_MIN;
  2697. else if (jcomp->quality > QUALITY_MAX)
  2698. sd->quality = QUALITY_MAX;
  2699. else
  2700. sd->quality = jcomp->quality;
  2701. if (gspca_dev->streaming)
  2702. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2703. return 0;
  2704. }
  2705. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  2706. struct v4l2_jpegcompression *jcomp)
  2707. {
  2708. struct sd *sd = (struct sd *) gspca_dev;
  2709. memset(jcomp, 0, sizeof *jcomp);
  2710. jcomp->quality = sd->quality;
  2711. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  2712. | V4L2_JPEG_MARKER_DQT;
  2713. return 0;
  2714. }
  2715. static int sd_querymenu(struct gspca_dev *gspca_dev,
  2716. struct v4l2_querymenu *menu)
  2717. {
  2718. switch (menu->id) {
  2719. case V4L2_CID_POWER_LINE_FREQUENCY:
  2720. switch (menu->index) {
  2721. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  2722. strcpy((char *) menu->name, "NoFliker");
  2723. return 0;
  2724. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  2725. strcpy((char *) menu->name, "50 Hz");
  2726. return 0;
  2727. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  2728. strcpy((char *) menu->name, "60 Hz");
  2729. return 0;
  2730. }
  2731. break;
  2732. }
  2733. return -EINVAL;
  2734. }
  2735. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2736. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2737. u8 *data, /* interrupt packet data */
  2738. int len) /* interrupt packet length */
  2739. {
  2740. int ret = -EINVAL;
  2741. if (len == 1 && data[0] == 1) {
  2742. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2743. input_sync(gspca_dev->input_dev);
  2744. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2745. input_sync(gspca_dev->input_dev);
  2746. ret = 0;
  2747. }
  2748. return ret;
  2749. }
  2750. #endif
  2751. /* sub-driver description */
  2752. static const struct sd_desc sd_desc = {
  2753. .name = MODULE_NAME,
  2754. .ctrls = sd_ctrls,
  2755. .nctrls = NCTRLS,
  2756. .config = sd_config,
  2757. .init = sd_init,
  2758. .start = sd_start,
  2759. .stopN = sd_stopN,
  2760. .pkt_scan = sd_pkt_scan,
  2761. .dq_callback = do_autogain,
  2762. .get_jcomp = sd_get_jcomp,
  2763. .set_jcomp = sd_set_jcomp,
  2764. .querymenu = sd_querymenu,
  2765. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2766. .int_pkt_scan = sd_int_pkt_scan,
  2767. #endif
  2768. };
  2769. /* -- module initialisation -- */
  2770. #define BS(bridge, sensor) \
  2771. .driver_info = (BRIDGE_ ## bridge << 16) \
  2772. | SENSOR_ ## sensor
  2773. static const __devinitdata struct usb_device_id device_table[] = {
  2774. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2775. {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
  2776. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2777. #endif
  2778. {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)},
  2779. {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)},
  2780. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2781. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2782. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2783. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2784. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2785. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2786. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2787. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2788. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2789. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2790. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2791. {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
  2792. /* or MT9V111 */
  2793. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2794. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2795. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2796. {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
  2797. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2798. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2799. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2800. /* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
  2801. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2802. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2803. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2804. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2805. #endif
  2806. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2807. {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
  2808. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2809. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2810. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2811. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2812. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2813. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2814. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2815. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2816. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2817. /*bw600.inf:*/
  2818. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2819. {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
  2820. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2821. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2822. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2823. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2824. /* or MT9V111 / MI0360B */
  2825. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2826. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2827. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2828. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2829. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2830. #endif
  2831. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2832. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2833. {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
  2834. /* or GC0305 / GC0307 */
  2835. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2836. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2837. {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/
  2838. {}
  2839. };
  2840. MODULE_DEVICE_TABLE(usb, device_table);
  2841. /* -- device connect -- */
  2842. static int sd_probe(struct usb_interface *intf,
  2843. const struct usb_device_id *id)
  2844. {
  2845. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2846. THIS_MODULE);
  2847. }
  2848. static struct usb_driver sd_driver = {
  2849. .name = MODULE_NAME,
  2850. .id_table = device_table,
  2851. .probe = sd_probe,
  2852. .disconnect = gspca_disconnect,
  2853. #ifdef CONFIG_PM
  2854. .suspend = gspca_suspend,
  2855. .resume = gspca_resume,
  2856. #endif
  2857. };
  2858. /* -- module insert / remove -- */
  2859. static int __init sd_mod_init(void)
  2860. {
  2861. return usb_register(&sd_driver);
  2862. }
  2863. static void __exit sd_mod_exit(void)
  2864. {
  2865. usb_deregister(&sd_driver);
  2866. }
  2867. module_init(sd_mod_init);
  2868. module_exit(sd_mod_exit);