sonixj.c 97 KB

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