sn9c20x.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431
  1. /*
  2. * Sonix sn9c201 sn9c202 library
  3. * Copyright (C) 2008-2009 microdia project <microdia@googlegroups.com>
  4. * Copyright (C) 2009 Brian Johnson <brijohn@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifdef CONFIG_INPUT
  21. #include <linux/input.h>
  22. #include <linux/slab.h>
  23. #endif
  24. #include "gspca.h"
  25. #include "jpeg.h"
  26. #include <media/v4l2-chip-ident.h>
  27. MODULE_AUTHOR("Brian Johnson <brijohn@gmail.com>, "
  28. "microdia project <microdia@googlegroups.com>");
  29. MODULE_DESCRIPTION("GSPCA/SN9C20X USB Camera Driver");
  30. MODULE_LICENSE("GPL");
  31. #define MODULE_NAME "sn9c20x"
  32. #define MODE_RAW 0x10
  33. #define MODE_JPEG 0x20
  34. #define MODE_SXGA 0x80
  35. #define SENSOR_OV9650 0
  36. #define SENSOR_OV9655 1
  37. #define SENSOR_SOI968 2
  38. #define SENSOR_OV7660 3
  39. #define SENSOR_OV7670 4
  40. #define SENSOR_MT9V011 5
  41. #define SENSOR_MT9V111 6
  42. #define SENSOR_MT9V112 7
  43. #define SENSOR_MT9M001 8
  44. #define SENSOR_MT9M111 9
  45. #define SENSOR_HV7131R 10
  46. #define SENSOR_MT9VPRB 20
  47. /* camera flags */
  48. #define HAS_BUTTON 0x1
  49. /* specific webcam descriptor */
  50. struct sd {
  51. struct gspca_dev gspca_dev;
  52. #define MIN_AVG_LUM 80
  53. #define MAX_AVG_LUM 130
  54. atomic_t avg_lum;
  55. u8 old_step;
  56. u8 older_step;
  57. u8 exposure_step;
  58. u8 brightness;
  59. u8 contrast;
  60. u8 saturation;
  61. s16 hue;
  62. u8 gamma;
  63. u8 red;
  64. u8 blue;
  65. u8 hflip;
  66. u8 vflip;
  67. u8 gain;
  68. u16 exposure;
  69. u8 auto_exposure;
  70. u8 i2c_addr;
  71. u8 sensor;
  72. u8 hstart;
  73. u8 vstart;
  74. u8 *jpeg_hdr;
  75. u8 quality;
  76. u8 flags;
  77. };
  78. struct i2c_reg_u8 {
  79. u8 reg;
  80. u8 val;
  81. };
  82. struct i2c_reg_u16 {
  83. u8 reg;
  84. u16 val;
  85. };
  86. static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val);
  87. static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val);
  88. static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val);
  89. static int sd_getcontrast(struct gspca_dev *gspca_dev, s32 *val);
  90. static int sd_setsaturation(struct gspca_dev *gspca_dev, s32 val);
  91. static int sd_getsaturation(struct gspca_dev *gspca_dev, s32 *val);
  92. static int sd_sethue(struct gspca_dev *gspca_dev, s32 val);
  93. static int sd_gethue(struct gspca_dev *gspca_dev, s32 *val);
  94. static int sd_setgamma(struct gspca_dev *gspca_dev, s32 val);
  95. static int sd_getgamma(struct gspca_dev *gspca_dev, s32 *val);
  96. static int sd_setredbalance(struct gspca_dev *gspca_dev, s32 val);
  97. static int sd_getredbalance(struct gspca_dev *gspca_dev, s32 *val);
  98. static int sd_setbluebalance(struct gspca_dev *gspca_dev, s32 val);
  99. static int sd_getbluebalance(struct gspca_dev *gspca_dev, s32 *val);
  100. static int sd_setvflip(struct gspca_dev *gspca_dev, s32 val);
  101. static int sd_getvflip(struct gspca_dev *gspca_dev, s32 *val);
  102. static int sd_sethflip(struct gspca_dev *gspca_dev, s32 val);
  103. static int sd_gethflip(struct gspca_dev *gspca_dev, s32 *val);
  104. static int sd_setgain(struct gspca_dev *gspca_dev, s32 val);
  105. static int sd_getgain(struct gspca_dev *gspca_dev, s32 *val);
  106. static int sd_setexposure(struct gspca_dev *gspca_dev, s32 val);
  107. static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val);
  108. static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val);
  109. static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val);
  110. static const struct ctrl sd_ctrls[] = {
  111. {
  112. #define BRIGHTNESS_IDX 0
  113. {
  114. .id = V4L2_CID_BRIGHTNESS,
  115. .type = V4L2_CTRL_TYPE_INTEGER,
  116. .name = "Brightness",
  117. .minimum = 0,
  118. .maximum = 0xff,
  119. .step = 1,
  120. #define BRIGHTNESS_DEFAULT 0x7f
  121. .default_value = BRIGHTNESS_DEFAULT,
  122. },
  123. .set = sd_setbrightness,
  124. .get = sd_getbrightness,
  125. },
  126. {
  127. #define CONTRAST_IDX 1
  128. {
  129. .id = V4L2_CID_CONTRAST,
  130. .type = V4L2_CTRL_TYPE_INTEGER,
  131. .name = "Contrast",
  132. .minimum = 0,
  133. .maximum = 0xff,
  134. .step = 1,
  135. #define CONTRAST_DEFAULT 0x7f
  136. .default_value = CONTRAST_DEFAULT,
  137. },
  138. .set = sd_setcontrast,
  139. .get = sd_getcontrast,
  140. },
  141. {
  142. #define SATURATION_IDX 2
  143. {
  144. .id = V4L2_CID_SATURATION,
  145. .type = V4L2_CTRL_TYPE_INTEGER,
  146. .name = "Saturation",
  147. .minimum = 0,
  148. .maximum = 0xff,
  149. .step = 1,
  150. #define SATURATION_DEFAULT 0x7f
  151. .default_value = SATURATION_DEFAULT,
  152. },
  153. .set = sd_setsaturation,
  154. .get = sd_getsaturation,
  155. },
  156. {
  157. #define HUE_IDX 3
  158. {
  159. .id = V4L2_CID_HUE,
  160. .type = V4L2_CTRL_TYPE_INTEGER,
  161. .name = "Hue",
  162. .minimum = -180,
  163. .maximum = 180,
  164. .step = 1,
  165. #define HUE_DEFAULT 0
  166. .default_value = HUE_DEFAULT,
  167. },
  168. .set = sd_sethue,
  169. .get = sd_gethue,
  170. },
  171. {
  172. #define GAMMA_IDX 4
  173. {
  174. .id = V4L2_CID_GAMMA,
  175. .type = V4L2_CTRL_TYPE_INTEGER,
  176. .name = "Gamma",
  177. .minimum = 0,
  178. .maximum = 0xff,
  179. .step = 1,
  180. #define GAMMA_DEFAULT 0x10
  181. .default_value = GAMMA_DEFAULT,
  182. },
  183. .set = sd_setgamma,
  184. .get = sd_getgamma,
  185. },
  186. {
  187. #define BLUE_IDX 5
  188. {
  189. .id = V4L2_CID_BLUE_BALANCE,
  190. .type = V4L2_CTRL_TYPE_INTEGER,
  191. .name = "Blue Balance",
  192. .minimum = 0,
  193. .maximum = 0x7f,
  194. .step = 1,
  195. #define BLUE_DEFAULT 0x28
  196. .default_value = BLUE_DEFAULT,
  197. },
  198. .set = sd_setbluebalance,
  199. .get = sd_getbluebalance,
  200. },
  201. {
  202. #define RED_IDX 6
  203. {
  204. .id = V4L2_CID_RED_BALANCE,
  205. .type = V4L2_CTRL_TYPE_INTEGER,
  206. .name = "Red Balance",
  207. .minimum = 0,
  208. .maximum = 0x7f,
  209. .step = 1,
  210. #define RED_DEFAULT 0x28
  211. .default_value = RED_DEFAULT,
  212. },
  213. .set = sd_setredbalance,
  214. .get = sd_getredbalance,
  215. },
  216. {
  217. #define HFLIP_IDX 7
  218. {
  219. .id = V4L2_CID_HFLIP,
  220. .type = V4L2_CTRL_TYPE_BOOLEAN,
  221. .name = "Horizontal Flip",
  222. .minimum = 0,
  223. .maximum = 1,
  224. .step = 1,
  225. #define HFLIP_DEFAULT 0
  226. .default_value = HFLIP_DEFAULT,
  227. },
  228. .set = sd_sethflip,
  229. .get = sd_gethflip,
  230. },
  231. {
  232. #define VFLIP_IDX 8
  233. {
  234. .id = V4L2_CID_VFLIP,
  235. .type = V4L2_CTRL_TYPE_BOOLEAN,
  236. .name = "Vertical Flip",
  237. .minimum = 0,
  238. .maximum = 1,
  239. .step = 1,
  240. #define VFLIP_DEFAULT 0
  241. .default_value = VFLIP_DEFAULT,
  242. },
  243. .set = sd_setvflip,
  244. .get = sd_getvflip,
  245. },
  246. {
  247. #define EXPOSURE_IDX 9
  248. {
  249. .id = V4L2_CID_EXPOSURE,
  250. .type = V4L2_CTRL_TYPE_INTEGER,
  251. .name = "Exposure",
  252. .minimum = 0,
  253. .maximum = 0x1780,
  254. .step = 1,
  255. #define EXPOSURE_DEFAULT 0x33
  256. .default_value = EXPOSURE_DEFAULT,
  257. },
  258. .set = sd_setexposure,
  259. .get = sd_getexposure,
  260. },
  261. {
  262. #define GAIN_IDX 10
  263. {
  264. .id = V4L2_CID_GAIN,
  265. .type = V4L2_CTRL_TYPE_INTEGER,
  266. .name = "Gain",
  267. .minimum = 0,
  268. .maximum = 28,
  269. .step = 1,
  270. #define GAIN_DEFAULT 0x00
  271. .default_value = GAIN_DEFAULT,
  272. },
  273. .set = sd_setgain,
  274. .get = sd_getgain,
  275. },
  276. {
  277. #define AUTOGAIN_IDX 11
  278. {
  279. .id = V4L2_CID_AUTOGAIN,
  280. .type = V4L2_CTRL_TYPE_BOOLEAN,
  281. .name = "Auto Exposure",
  282. .minimum = 0,
  283. .maximum = 1,
  284. .step = 1,
  285. #define AUTO_EXPOSURE_DEFAULT 1
  286. .default_value = AUTO_EXPOSURE_DEFAULT,
  287. },
  288. .set = sd_setautoexposure,
  289. .get = sd_getautoexposure,
  290. },
  291. };
  292. static const struct v4l2_pix_format vga_mode[] = {
  293. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  294. .bytesperline = 240,
  295. .sizeimage = 240 * 120,
  296. .colorspace = V4L2_COLORSPACE_JPEG,
  297. .priv = 0 | MODE_JPEG},
  298. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  299. .bytesperline = 160,
  300. .sizeimage = 160 * 120,
  301. .colorspace = V4L2_COLORSPACE_SRGB,
  302. .priv = 0 | MODE_RAW},
  303. {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  304. .bytesperline = 240,
  305. .sizeimage = 240 * 120,
  306. .colorspace = V4L2_COLORSPACE_SRGB,
  307. .priv = 0},
  308. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  309. .bytesperline = 480,
  310. .sizeimage = 480 * 240 ,
  311. .colorspace = V4L2_COLORSPACE_JPEG,
  312. .priv = 1 | MODE_JPEG},
  313. {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  314. .bytesperline = 320,
  315. .sizeimage = 320 * 240 ,
  316. .colorspace = V4L2_COLORSPACE_SRGB,
  317. .priv = 1 | MODE_RAW},
  318. {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  319. .bytesperline = 480,
  320. .sizeimage = 480 * 240 ,
  321. .colorspace = V4L2_COLORSPACE_SRGB,
  322. .priv = 1},
  323. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  324. .bytesperline = 960,
  325. .sizeimage = 960 * 480,
  326. .colorspace = V4L2_COLORSPACE_JPEG,
  327. .priv = 2 | MODE_JPEG},
  328. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  329. .bytesperline = 640,
  330. .sizeimage = 640 * 480,
  331. .colorspace = V4L2_COLORSPACE_SRGB,
  332. .priv = 2 | MODE_RAW},
  333. {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  334. .bytesperline = 960,
  335. .sizeimage = 960 * 480,
  336. .colorspace = V4L2_COLORSPACE_SRGB,
  337. .priv = 2},
  338. };
  339. static const struct v4l2_pix_format sxga_mode[] = {
  340. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  341. .bytesperline = 240,
  342. .sizeimage = 240 * 120,
  343. .colorspace = V4L2_COLORSPACE_JPEG,
  344. .priv = 0 | MODE_JPEG},
  345. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  346. .bytesperline = 160,
  347. .sizeimage = 160 * 120,
  348. .colorspace = V4L2_COLORSPACE_SRGB,
  349. .priv = 0 | MODE_RAW},
  350. {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  351. .bytesperline = 240,
  352. .sizeimage = 240 * 120,
  353. .colorspace = V4L2_COLORSPACE_SRGB,
  354. .priv = 0},
  355. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  356. .bytesperline = 480,
  357. .sizeimage = 480 * 240 ,
  358. .colorspace = V4L2_COLORSPACE_JPEG,
  359. .priv = 1 | MODE_JPEG},
  360. {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  361. .bytesperline = 320,
  362. .sizeimage = 320 * 240 ,
  363. .colorspace = V4L2_COLORSPACE_SRGB,
  364. .priv = 1 | MODE_RAW},
  365. {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  366. .bytesperline = 480,
  367. .sizeimage = 480 * 240 ,
  368. .colorspace = V4L2_COLORSPACE_SRGB,
  369. .priv = 1},
  370. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  371. .bytesperline = 960,
  372. .sizeimage = 960 * 480,
  373. .colorspace = V4L2_COLORSPACE_JPEG,
  374. .priv = 2 | MODE_JPEG},
  375. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  376. .bytesperline = 640,
  377. .sizeimage = 640 * 480,
  378. .colorspace = V4L2_COLORSPACE_SRGB,
  379. .priv = 2 | MODE_RAW},
  380. {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  381. .bytesperline = 960,
  382. .sizeimage = 960 * 480,
  383. .colorspace = V4L2_COLORSPACE_SRGB,
  384. .priv = 2},
  385. {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  386. .bytesperline = 1280,
  387. .sizeimage = (1280 * 1024) + 64,
  388. .colorspace = V4L2_COLORSPACE_SRGB,
  389. .priv = 3 | MODE_RAW | MODE_SXGA},
  390. };
  391. static const s16 hsv_red_x[] = {
  392. 41, 44, 46, 48, 50, 52, 54, 56,
  393. 58, 60, 62, 64, 66, 68, 70, 72,
  394. 74, 76, 78, 80, 81, 83, 85, 87,
  395. 88, 90, 92, 93, 95, 97, 98, 100,
  396. 101, 102, 104, 105, 107, 108, 109, 110,
  397. 112, 113, 114, 115, 116, 117, 118, 119,
  398. 120, 121, 122, 123, 123, 124, 125, 125,
  399. 126, 127, 127, 128, 128, 129, 129, 129,
  400. 130, 130, 130, 130, 131, 131, 131, 131,
  401. 131, 131, 131, 131, 130, 130, 130, 130,
  402. 129, 129, 129, 128, 128, 127, 127, 126,
  403. 125, 125, 124, 123, 122, 122, 121, 120,
  404. 119, 118, 117, 116, 115, 114, 112, 111,
  405. 110, 109, 107, 106, 105, 103, 102, 101,
  406. 99, 98, 96, 94, 93, 91, 90, 88,
  407. 86, 84, 83, 81, 79, 77, 75, 74,
  408. 72, 70, 68, 66, 64, 62, 60, 58,
  409. 56, 54, 52, 49, 47, 45, 43, 41,
  410. 39, 36, 34, 32, 30, 28, 25, 23,
  411. 21, 19, 16, 14, 12, 9, 7, 5,
  412. 3, 0, -1, -3, -6, -8, -10, -12,
  413. -15, -17, -19, -22, -24, -26, -28, -30,
  414. -33, -35, -37, -39, -41, -44, -46, -48,
  415. -50, -52, -54, -56, -58, -60, -62, -64,
  416. -66, -68, -70, -72, -74, -76, -78, -80,
  417. -81, -83, -85, -87, -88, -90, -92, -93,
  418. -95, -97, -98, -100, -101, -102, -104, -105,
  419. -107, -108, -109, -110, -112, -113, -114, -115,
  420. -116, -117, -118, -119, -120, -121, -122, -123,
  421. -123, -124, -125, -125, -126, -127, -127, -128,
  422. -128, -128, -128, -128, -128, -128, -128, -128,
  423. -128, -128, -128, -128, -128, -128, -128, -128,
  424. -128, -128, -128, -128, -128, -128, -128, -128,
  425. -128, -127, -127, -126, -125, -125, -124, -123,
  426. -122, -122, -121, -120, -119, -118, -117, -116,
  427. -115, -114, -112, -111, -110, -109, -107, -106,
  428. -105, -103, -102, -101, -99, -98, -96, -94,
  429. -93, -91, -90, -88, -86, -84, -83, -81,
  430. -79, -77, -75, -74, -72, -70, -68, -66,
  431. -64, -62, -60, -58, -56, -54, -52, -49,
  432. -47, -45, -43, -41, -39, -36, -34, -32,
  433. -30, -28, -25, -23, -21, -19, -16, -14,
  434. -12, -9, -7, -5, -3, 0, 1, 3,
  435. 6, 8, 10, 12, 15, 17, 19, 22,
  436. 24, 26, 28, 30, 33, 35, 37, 39, 41
  437. };
  438. static const s16 hsv_red_y[] = {
  439. 82, 80, 78, 76, 74, 73, 71, 69,
  440. 67, 65, 63, 61, 58, 56, 54, 52,
  441. 50, 48, 46, 44, 41, 39, 37, 35,
  442. 32, 30, 28, 26, 23, 21, 19, 16,
  443. 14, 12, 10, 7, 5, 3, 0, -1,
  444. -3, -6, -8, -10, -13, -15, -17, -19,
  445. -22, -24, -26, -29, -31, -33, -35, -38,
  446. -40, -42, -44, -46, -48, -51, -53, -55,
  447. -57, -59, -61, -63, -65, -67, -69, -71,
  448. -73, -75, -77, -79, -81, -82, -84, -86,
  449. -88, -89, -91, -93, -94, -96, -98, -99,
  450. -101, -102, -104, -105, -106, -108, -109, -110,
  451. -112, -113, -114, -115, -116, -117, -119, -120,
  452. -120, -121, -122, -123, -124, -125, -126, -126,
  453. -127, -128, -128, -128, -128, -128, -128, -128,
  454. -128, -128, -128, -128, -128, -128, -128, -128,
  455. -128, -128, -128, -128, -128, -128, -128, -128,
  456. -128, -128, -128, -128, -128, -128, -128, -128,
  457. -127, -127, -126, -125, -125, -124, -123, -122,
  458. -121, -120, -119, -118, -117, -116, -115, -114,
  459. -113, -111, -110, -109, -107, -106, -105, -103,
  460. -102, -100, -99, -97, -96, -94, -92, -91,
  461. -89, -87, -85, -84, -82, -80, -78, -76,
  462. -74, -73, -71, -69, -67, -65, -63, -61,
  463. -58, -56, -54, -52, -50, -48, -46, -44,
  464. -41, -39, -37, -35, -32, -30, -28, -26,
  465. -23, -21, -19, -16, -14, -12, -10, -7,
  466. -5, -3, 0, 1, 3, 6, 8, 10,
  467. 13, 15, 17, 19, 22, 24, 26, 29,
  468. 31, 33, 35, 38, 40, 42, 44, 46,
  469. 48, 51, 53, 55, 57, 59, 61, 63,
  470. 65, 67, 69, 71, 73, 75, 77, 79,
  471. 81, 82, 84, 86, 88, 89, 91, 93,
  472. 94, 96, 98, 99, 101, 102, 104, 105,
  473. 106, 108, 109, 110, 112, 113, 114, 115,
  474. 116, 117, 119, 120, 120, 121, 122, 123,
  475. 124, 125, 126, 126, 127, 128, 128, 129,
  476. 129, 130, 130, 131, 131, 131, 131, 132,
  477. 132, 132, 132, 132, 132, 132, 132, 132,
  478. 132, 132, 132, 131, 131, 131, 130, 130,
  479. 130, 129, 129, 128, 127, 127, 126, 125,
  480. 125, 124, 123, 122, 121, 120, 119, 118,
  481. 117, 116, 115, 114, 113, 111, 110, 109,
  482. 107, 106, 105, 103, 102, 100, 99, 97,
  483. 96, 94, 92, 91, 89, 87, 85, 84, 82
  484. };
  485. static const s16 hsv_green_x[] = {
  486. -124, -124, -125, -125, -125, -125, -125, -125,
  487. -125, -126, -126, -125, -125, -125, -125, -125,
  488. -125, -124, -124, -124, -123, -123, -122, -122,
  489. -121, -121, -120, -120, -119, -118, -117, -117,
  490. -116, -115, -114, -113, -112, -111, -110, -109,
  491. -108, -107, -105, -104, -103, -102, -100, -99,
  492. -98, -96, -95, -93, -92, -91, -89, -87,
  493. -86, -84, -83, -81, -79, -77, -76, -74,
  494. -72, -70, -69, -67, -65, -63, -61, -59,
  495. -57, -55, -53, -51, -49, -47, -45, -43,
  496. -41, -39, -37, -35, -33, -30, -28, -26,
  497. -24, -22, -20, -18, -15, -13, -11, -9,
  498. -7, -4, -2, 0, 1, 3, 6, 8,
  499. 10, 12, 14, 17, 19, 21, 23, 25,
  500. 27, 29, 32, 34, 36, 38, 40, 42,
  501. 44, 46, 48, 50, 52, 54, 56, 58,
  502. 60, 62, 64, 66, 68, 70, 71, 73,
  503. 75, 77, 78, 80, 82, 83, 85, 87,
  504. 88, 90, 91, 93, 94, 96, 97, 98,
  505. 100, 101, 102, 104, 105, 106, 107, 108,
  506. 109, 111, 112, 113, 113, 114, 115, 116,
  507. 117, 118, 118, 119, 120, 120, 121, 122,
  508. 122, 123, 123, 124, 124, 124, 125, 125,
  509. 125, 125, 125, 125, 125, 126, 126, 125,
  510. 125, 125, 125, 125, 125, 124, 124, 124,
  511. 123, 123, 122, 122, 121, 121, 120, 120,
  512. 119, 118, 117, 117, 116, 115, 114, 113,
  513. 112, 111, 110, 109, 108, 107, 105, 104,
  514. 103, 102, 100, 99, 98, 96, 95, 93,
  515. 92, 91, 89, 87, 86, 84, 83, 81,
  516. 79, 77, 76, 74, 72, 70, 69, 67,
  517. 65, 63, 61, 59, 57, 55, 53, 51,
  518. 49, 47, 45, 43, 41, 39, 37, 35,
  519. 33, 30, 28, 26, 24, 22, 20, 18,
  520. 15, 13, 11, 9, 7, 4, 2, 0,
  521. -1, -3, -6, -8, -10, -12, -14, -17,
  522. -19, -21, -23, -25, -27, -29, -32, -34,
  523. -36, -38, -40, -42, -44, -46, -48, -50,
  524. -52, -54, -56, -58, -60, -62, -64, -66,
  525. -68, -70, -71, -73, -75, -77, -78, -80,
  526. -82, -83, -85, -87, -88, -90, -91, -93,
  527. -94, -96, -97, -98, -100, -101, -102, -104,
  528. -105, -106, -107, -108, -109, -111, -112, -113,
  529. -113, -114, -115, -116, -117, -118, -118, -119,
  530. -120, -120, -121, -122, -122, -123, -123, -124, -124
  531. };
  532. static const s16 hsv_green_y[] = {
  533. -100, -99, -98, -97, -95, -94, -93, -91,
  534. -90, -89, -87, -86, -84, -83, -81, -80,
  535. -78, -76, -75, -73, -71, -70, -68, -66,
  536. -64, -63, -61, -59, -57, -55, -53, -51,
  537. -49, -48, -46, -44, -42, -40, -38, -36,
  538. -34, -32, -30, -27, -25, -23, -21, -19,
  539. -17, -15, -13, -11, -9, -7, -4, -2,
  540. 0, 1, 3, 5, 7, 9, 11, 14,
  541. 16, 18, 20, 22, 24, 26, 28, 30,
  542. 32, 34, 36, 38, 40, 42, 44, 46,
  543. 48, 50, 52, 54, 56, 58, 59, 61,
  544. 63, 65, 67, 68, 70, 72, 74, 75,
  545. 77, 78, 80, 82, 83, 85, 86, 88,
  546. 89, 90, 92, 93, 95, 96, 97, 98,
  547. 100, 101, 102, 103, 104, 105, 106, 107,
  548. 108, 109, 110, 111, 112, 112, 113, 114,
  549. 115, 115, 116, 116, 117, 117, 118, 118,
  550. 119, 119, 119, 120, 120, 120, 120, 120,
  551. 121, 121, 121, 121, 121, 121, 120, 120,
  552. 120, 120, 120, 119, 119, 119, 118, 118,
  553. 117, 117, 116, 116, 115, 114, 114, 113,
  554. 112, 111, 111, 110, 109, 108, 107, 106,
  555. 105, 104, 103, 102, 100, 99, 98, 97,
  556. 95, 94, 93, 91, 90, 89, 87, 86,
  557. 84, 83, 81, 80, 78, 76, 75, 73,
  558. 71, 70, 68, 66, 64, 63, 61, 59,
  559. 57, 55, 53, 51, 49, 48, 46, 44,
  560. 42, 40, 38, 36, 34, 32, 30, 27,
  561. 25, 23, 21, 19, 17, 15, 13, 11,
  562. 9, 7, 4, 2, 0, -1, -3, -5,
  563. -7, -9, -11, -14, -16, -18, -20, -22,
  564. -24, -26, -28, -30, -32, -34, -36, -38,
  565. -40, -42, -44, -46, -48, -50, -52, -54,
  566. -56, -58, -59, -61, -63, -65, -67, -68,
  567. -70, -72, -74, -75, -77, -78, -80, -82,
  568. -83, -85, -86, -88, -89, -90, -92, -93,
  569. -95, -96, -97, -98, -100, -101, -102, -103,
  570. -104, -105, -106, -107, -108, -109, -110, -111,
  571. -112, -112, -113, -114, -115, -115, -116, -116,
  572. -117, -117, -118, -118, -119, -119, -119, -120,
  573. -120, -120, -120, -120, -121, -121, -121, -121,
  574. -121, -121, -120, -120, -120, -120, -120, -119,
  575. -119, -119, -118, -118, -117, -117, -116, -116,
  576. -115, -114, -114, -113, -112, -111, -111, -110,
  577. -109, -108, -107, -106, -105, -104, -103, -102, -100
  578. };
  579. static const s16 hsv_blue_x[] = {
  580. 112, 113, 114, 114, 115, 116, 117, 117,
  581. 118, 118, 119, 119, 120, 120, 120, 121,
  582. 121, 121, 122, 122, 122, 122, 122, 122,
  583. 122, 122, 122, 122, 122, 122, 121, 121,
  584. 121, 120, 120, 120, 119, 119, 118, 118,
  585. 117, 116, 116, 115, 114, 113, 113, 112,
  586. 111, 110, 109, 108, 107, 106, 105, 104,
  587. 103, 102, 100, 99, 98, 97, 95, 94,
  588. 93, 91, 90, 88, 87, 85, 84, 82,
  589. 80, 79, 77, 76, 74, 72, 70, 69,
  590. 67, 65, 63, 61, 60, 58, 56, 54,
  591. 52, 50, 48, 46, 44, 42, 40, 38,
  592. 36, 34, 32, 30, 28, 26, 24, 22,
  593. 19, 17, 15, 13, 11, 9, 7, 5,
  594. 2, 0, -1, -3, -5, -7, -9, -12,
  595. -14, -16, -18, -20, -22, -24, -26, -28,
  596. -31, -33, -35, -37, -39, -41, -43, -45,
  597. -47, -49, -51, -53, -54, -56, -58, -60,
  598. -62, -64, -66, -67, -69, -71, -73, -74,
  599. -76, -78, -79, -81, -83, -84, -86, -87,
  600. -89, -90, -92, -93, -94, -96, -97, -98,
  601. -99, -101, -102, -103, -104, -105, -106, -107,
  602. -108, -109, -110, -111, -112, -113, -114, -114,
  603. -115, -116, -117, -117, -118, -118, -119, -119,
  604. -120, -120, -120, -121, -121, -121, -122, -122,
  605. -122, -122, -122, -122, -122, -122, -122, -122,
  606. -122, -122, -121, -121, -121, -120, -120, -120,
  607. -119, -119, -118, -118, -117, -116, -116, -115,
  608. -114, -113, -113, -112, -111, -110, -109, -108,
  609. -107, -106, -105, -104, -103, -102, -100, -99,
  610. -98, -97, -95, -94, -93, -91, -90, -88,
  611. -87, -85, -84, -82, -80, -79, -77, -76,
  612. -74, -72, -70, -69, -67, -65, -63, -61,
  613. -60, -58, -56, -54, -52, -50, -48, -46,
  614. -44, -42, -40, -38, -36, -34, -32, -30,
  615. -28, -26, -24, -22, -19, -17, -15, -13,
  616. -11, -9, -7, -5, -2, 0, 1, 3,
  617. 5, 7, 9, 12, 14, 16, 18, 20,
  618. 22, 24, 26, 28, 31, 33, 35, 37,
  619. 39, 41, 43, 45, 47, 49, 51, 53,
  620. 54, 56, 58, 60, 62, 64, 66, 67,
  621. 69, 71, 73, 74, 76, 78, 79, 81,
  622. 83, 84, 86, 87, 89, 90, 92, 93,
  623. 94, 96, 97, 98, 99, 101, 102, 103,
  624. 104, 105, 106, 107, 108, 109, 110, 111, 112
  625. };
  626. static const s16 hsv_blue_y[] = {
  627. -11, -13, -15, -17, -19, -21, -23, -25,
  628. -27, -29, -31, -33, -35, -37, -39, -41,
  629. -43, -45, -46, -48, -50, -52, -54, -55,
  630. -57, -59, -61, -62, -64, -66, -67, -69,
  631. -71, -72, -74, -75, -77, -78, -80, -81,
  632. -83, -84, -86, -87, -88, -90, -91, -92,
  633. -93, -95, -96, -97, -98, -99, -100, -101,
  634. -102, -103, -104, -105, -106, -106, -107, -108,
  635. -109, -109, -110, -111, -111, -112, -112, -113,
  636. -113, -114, -114, -114, -115, -115, -115, -115,
  637. -116, -116, -116, -116, -116, -116, -116, -116,
  638. -116, -115, -115, -115, -115, -114, -114, -114,
  639. -113, -113, -112, -112, -111, -111, -110, -110,
  640. -109, -108, -108, -107, -106, -105, -104, -103,
  641. -102, -101, -100, -99, -98, -97, -96, -95,
  642. -94, -93, -91, -90, -89, -88, -86, -85,
  643. -84, -82, -81, -79, -78, -76, -75, -73,
  644. -71, -70, -68, -67, -65, -63, -62, -60,
  645. -58, -56, -55, -53, -51, -49, -47, -45,
  646. -44, -42, -40, -38, -36, -34, -32, -30,
  647. -28, -26, -24, -22, -20, -18, -16, -14,
  648. -12, -10, -8, -6, -4, -2, 0, 1,
  649. 3, 5, 7, 9, 11, 13, 15, 17,
  650. 19, 21, 23, 25, 27, 29, 31, 33,
  651. 35, 37, 39, 41, 43, 45, 46, 48,
  652. 50, 52, 54, 55, 57, 59, 61, 62,
  653. 64, 66, 67, 69, 71, 72, 74, 75,
  654. 77, 78, 80, 81, 83, 84, 86, 87,
  655. 88, 90, 91, 92, 93, 95, 96, 97,
  656. 98, 99, 100, 101, 102, 103, 104, 105,
  657. 106, 106, 107, 108, 109, 109, 110, 111,
  658. 111, 112, 112, 113, 113, 114, 114, 114,
  659. 115, 115, 115, 115, 116, 116, 116, 116,
  660. 116, 116, 116, 116, 116, 115, 115, 115,
  661. 115, 114, 114, 114, 113, 113, 112, 112,
  662. 111, 111, 110, 110, 109, 108, 108, 107,
  663. 106, 105, 104, 103, 102, 101, 100, 99,
  664. 98, 97, 96, 95, 94, 93, 91, 90,
  665. 89, 88, 86, 85, 84, 82, 81, 79,
  666. 78, 76, 75, 73, 71, 70, 68, 67,
  667. 65, 63, 62, 60, 58, 56, 55, 53,
  668. 51, 49, 47, 45, 44, 42, 40, 38,
  669. 36, 34, 32, 30, 28, 26, 24, 22,
  670. 20, 18, 16, 14, 12, 10, 8, 6,
  671. 4, 2, 0, -1, -3, -5, -7, -9, -11
  672. };
  673. static u16 i2c_ident[] = {
  674. V4L2_IDENT_OV9650,
  675. V4L2_IDENT_OV9655,
  676. V4L2_IDENT_SOI968,
  677. V4L2_IDENT_OV7660,
  678. V4L2_IDENT_OV7670,
  679. V4L2_IDENT_MT9V011,
  680. V4L2_IDENT_MT9V111,
  681. V4L2_IDENT_MT9V112,
  682. V4L2_IDENT_MT9M001C12ST,
  683. V4L2_IDENT_MT9M111,
  684. V4L2_IDENT_HV7131R,
  685. };
  686. static u16 bridge_init[][2] = {
  687. {0x1000, 0x78}, {0x1001, 0x40}, {0x1002, 0x1c},
  688. {0x1020, 0x80}, {0x1061, 0x01}, {0x1067, 0x40},
  689. {0x1068, 0x30}, {0x1069, 0x20}, {0x106a, 0x10},
  690. {0x106b, 0x08}, {0x1188, 0x87}, {0x11a1, 0x00},
  691. {0x11a2, 0x00}, {0x11a3, 0x6a}, {0x11a4, 0x50},
  692. {0x11ab, 0x00}, {0x11ac, 0x00}, {0x11ad, 0x50},
  693. {0x11ae, 0x3c}, {0x118a, 0x04}, {0x0395, 0x04},
  694. {0x11b8, 0x3a}, {0x118b, 0x0e}, {0x10f7, 0x05},
  695. {0x10f8, 0x14}, {0x10fa, 0xff}, {0x10f9, 0x00},
  696. {0x11ba, 0x0a}, {0x11a5, 0x2d}, {0x11a6, 0x2d},
  697. {0x11a7, 0x3a}, {0x11a8, 0x05}, {0x11a9, 0x04},
  698. {0x11aa, 0x3f}, {0x11af, 0x28}, {0x11b0, 0xd8},
  699. {0x11b1, 0x14}, {0x11b2, 0xec}, {0x11b3, 0x32},
  700. {0x11b4, 0xdd}, {0x11b5, 0x32}, {0x11b6, 0xdd},
  701. {0x10e0, 0x2c}, {0x11bc, 0x40}, {0x11bd, 0x01},
  702. {0x11be, 0xf0}, {0x11bf, 0x00}, {0x118c, 0x1f},
  703. {0x118d, 0x1f}, {0x118e, 0x1f}, {0x118f, 0x1f},
  704. {0x1180, 0x01}, {0x1181, 0x00}, {0x1182, 0x01},
  705. {0x1183, 0x00}, {0x1184, 0x50}, {0x1185, 0x80}
  706. };
  707. /* Gain = (bit[3:0] / 16 + 1) * (bit[4] + 1) * (bit[5] + 1) * (bit[6] + 1) */
  708. static u8 ov_gain[] = {
  709. 0x00 /* 1x */, 0x04 /* 1.25x */, 0x08 /* 1.5x */, 0x0c /* 1.75x */,
  710. 0x10 /* 2x */, 0x12 /* 2.25x */, 0x14 /* 2.5x */, 0x16 /* 2.75x */,
  711. 0x18 /* 3x */, 0x1a /* 3.25x */, 0x1c /* 3.5x */, 0x1e /* 3.75x */,
  712. 0x30 /* 4x */, 0x31 /* 4.25x */, 0x32 /* 4.5x */, 0x33 /* 4.75x */,
  713. 0x34 /* 5x */, 0x35 /* 5.25x */, 0x36 /* 5.5x */, 0x37 /* 5.75x */,
  714. 0x38 /* 6x */, 0x39 /* 6.25x */, 0x3a /* 6.5x */, 0x3b /* 6.75x */,
  715. 0x3c /* 7x */, 0x3d /* 7.25x */, 0x3e /* 7.5x */, 0x3f /* 7.75x */,
  716. 0x70 /* 8x */
  717. };
  718. /* Gain = (bit[8] + 1) * (bit[7] + 1) * (bit[6:0] * 0.03125) */
  719. static u16 micron1_gain[] = {
  720. /* 1x 1.25x 1.5x 1.75x */
  721. 0x0020, 0x0028, 0x0030, 0x0038,
  722. /* 2x 2.25x 2.5x 2.75x */
  723. 0x00a0, 0x00a4, 0x00a8, 0x00ac,
  724. /* 3x 3.25x 3.5x 3.75x */
  725. 0x00b0, 0x00b4, 0x00b8, 0x00bc,
  726. /* 4x 4.25x 4.5x 4.75x */
  727. 0x00c0, 0x00c4, 0x00c8, 0x00cc,
  728. /* 5x 5.25x 5.5x 5.75x */
  729. 0x00d0, 0x00d4, 0x00d8, 0x00dc,
  730. /* 6x 6.25x 6.5x 6.75x */
  731. 0x00e0, 0x00e4, 0x00e8, 0x00ec,
  732. /* 7x 7.25x 7.5x 7.75x */
  733. 0x00f0, 0x00f4, 0x00f8, 0x00fc,
  734. /* 8x */
  735. 0x01c0
  736. };
  737. /* mt9m001 sensor uses a different gain formula then other micron sensors */
  738. /* Gain = (bit[6] + 1) * (bit[5-0] * 0.125) */
  739. static u16 micron2_gain[] = {
  740. /* 1x 1.25x 1.5x 1.75x */
  741. 0x0008, 0x000a, 0x000c, 0x000e,
  742. /* 2x 2.25x 2.5x 2.75x */
  743. 0x0010, 0x0012, 0x0014, 0x0016,
  744. /* 3x 3.25x 3.5x 3.75x */
  745. 0x0018, 0x001a, 0x001c, 0x001e,
  746. /* 4x 4.25x 4.5x 4.75x */
  747. 0x0020, 0x0051, 0x0052, 0x0053,
  748. /* 5x 5.25x 5.5x 5.75x */
  749. 0x0054, 0x0055, 0x0056, 0x0057,
  750. /* 6x 6.25x 6.5x 6.75x */
  751. 0x0058, 0x0059, 0x005a, 0x005b,
  752. /* 7x 7.25x 7.5x 7.75x */
  753. 0x005c, 0x005d, 0x005e, 0x005f,
  754. /* 8x */
  755. 0x0060
  756. };
  757. /* Gain = .5 + bit[7:0] / 16 */
  758. static u8 hv7131r_gain[] = {
  759. 0x08 /* 1x */, 0x0c /* 1.25x */, 0x10 /* 1.5x */, 0x14 /* 1.75x */,
  760. 0x18 /* 2x */, 0x1c /* 2.25x */, 0x20 /* 2.5x */, 0x24 /* 2.75x */,
  761. 0x28 /* 3x */, 0x2c /* 3.25x */, 0x30 /* 3.5x */, 0x34 /* 3.75x */,
  762. 0x38 /* 4x */, 0x3c /* 4.25x */, 0x40 /* 4.5x */, 0x44 /* 4.75x */,
  763. 0x48 /* 5x */, 0x4c /* 5.25x */, 0x50 /* 5.5x */, 0x54 /* 5.75x */,
  764. 0x58 /* 6x */, 0x5c /* 6.25x */, 0x60 /* 6.5x */, 0x64 /* 6.75x */,
  765. 0x68 /* 7x */, 0x6c /* 7.25x */, 0x70 /* 7.5x */, 0x74 /* 7.75x */,
  766. 0x78 /* 8x */
  767. };
  768. static struct i2c_reg_u8 soi968_init[] = {
  769. {0x12, 0x80}, {0x0c, 0x00}, {0x0f, 0x1f},
  770. {0x11, 0x80}, {0x38, 0x52}, {0x1e, 0x00},
  771. {0x33, 0x08}, {0x35, 0x8c}, {0x36, 0x0c},
  772. {0x37, 0x04}, {0x45, 0x04}, {0x47, 0xff},
  773. {0x3e, 0x00}, {0x3f, 0x00}, {0x3b, 0x20},
  774. {0x3a, 0x96}, {0x3d, 0x0a}, {0x14, 0x8e},
  775. {0x13, 0x8b}, {0x12, 0x40}, {0x17, 0x13},
  776. {0x18, 0x63}, {0x19, 0x01}, {0x1a, 0x79},
  777. {0x32, 0x24}, {0x03, 0x00}, {0x11, 0x40},
  778. {0x2a, 0x10}, {0x2b, 0xe0}, {0x10, 0x32},
  779. {0x00, 0x00}, {0x01, 0x80}, {0x02, 0x80},
  780. };
  781. static struct i2c_reg_u8 ov7660_init[] = {
  782. {0x0e, 0x80}, {0x0d, 0x08}, {0x0f, 0xc3},
  783. {0x04, 0xc3}, {0x10, 0x40}, {0x11, 0x40},
  784. {0x12, 0x05}, {0x13, 0xba}, {0x14, 0x2a},
  785. {0x37, 0x0f}, {0x38, 0x02}, {0x39, 0x43},
  786. {0x3a, 0x00}, {0x69, 0x90}, {0x2d, 0xf6},
  787. {0x2e, 0x0b}, {0x01, 0x78}, {0x02, 0x50},
  788. };
  789. static struct i2c_reg_u8 ov7670_init[] = {
  790. {0x12, 0x80}, {0x11, 0x80}, {0x3a, 0x04}, {0x12, 0x01},
  791. {0x32, 0xb6}, {0x03, 0x0a}, {0x0c, 0x00}, {0x3e, 0x00},
  792. {0x70, 0x3a}, {0x71, 0x35}, {0x72, 0x11}, {0x73, 0xf0},
  793. {0xa2, 0x02}, {0x13, 0xe0}, {0x00, 0x00}, {0x10, 0x00},
  794. {0x0d, 0x40}, {0x14, 0x28}, {0xa5, 0x05}, {0xab, 0x07},
  795. {0x24, 0x95}, {0x25, 0x33}, {0x26, 0xe3}, {0x9f, 0x75},
  796. {0xa0, 0x65}, {0xa1, 0x0b}, {0xa6, 0xd8}, {0xa7, 0xd8},
  797. {0xa8, 0xf0}, {0xa9, 0x90}, {0xaa, 0x94}, {0x13, 0xe5},
  798. {0x0e, 0x61}, {0x0f, 0x4b}, {0x16, 0x02}, {0x1e, 0x27},
  799. {0x21, 0x02}, {0x22, 0x91}, {0x29, 0x07}, {0x33, 0x0b},
  800. {0x35, 0x0b}, {0x37, 0x1d}, {0x38, 0x71}, {0x39, 0x2a},
  801. {0x3c, 0x78}, {0x4d, 0x40}, {0x4e, 0x20}, {0x69, 0x00},
  802. {0x74, 0x19}, {0x8d, 0x4f}, {0x8e, 0x00}, {0x8f, 0x00},
  803. {0x90, 0x00}, {0x91, 0x00}, {0x96, 0x00}, {0x9a, 0x80},
  804. {0xb0, 0x84}, {0xb1, 0x0c}, {0xb2, 0x0e}, {0xb3, 0x82},
  805. {0xb8, 0x0a}, {0x43, 0x0a}, {0x44, 0xf0}, {0x45, 0x20},
  806. {0x46, 0x7d}, {0x47, 0x29}, {0x48, 0x4a}, {0x59, 0x8c},
  807. {0x5a, 0xa5}, {0x5b, 0xde}, {0x5c, 0x96}, {0x5d, 0x66},
  808. {0x5e, 0x10}, {0x6c, 0x0a}, {0x6d, 0x55}, {0x6e, 0x11},
  809. {0x6f, 0x9e}, {0x6a, 0x40}, {0x01, 0x40}, {0x02, 0x40},
  810. {0x13, 0xe7}, {0x4f, 0x6e}, {0x50, 0x70}, {0x51, 0x02},
  811. {0x52, 0x1d}, {0x53, 0x56}, {0x54, 0x73}, {0x55, 0x0a},
  812. {0x56, 0x55}, {0x57, 0x80}, {0x58, 0x9e}, {0x41, 0x08},
  813. {0x3f, 0x02}, {0x75, 0x03}, {0x76, 0x63}, {0x4c, 0x04},
  814. {0x77, 0x06}, {0x3d, 0x02}, {0x4b, 0x09}, {0xc9, 0x30},
  815. {0x41, 0x08}, {0x56, 0x48}, {0x34, 0x11}, {0xa4, 0x88},
  816. {0x96, 0x00}, {0x97, 0x30}, {0x98, 0x20}, {0x99, 0x30},
  817. {0x9a, 0x84}, {0x9b, 0x29}, {0x9c, 0x03}, {0x9d, 0x99},
  818. {0x9e, 0x7f}, {0x78, 0x04}, {0x79, 0x01}, {0xc8, 0xf0},
  819. {0x79, 0x0f}, {0xc8, 0x00}, {0x79, 0x10}, {0xc8, 0x7e},
  820. {0x79, 0x0a}, {0xc8, 0x80}, {0x79, 0x0b}, {0xc8, 0x01},
  821. {0x79, 0x0c}, {0xc8, 0x0f}, {0x79, 0x0d}, {0xc8, 0x20},
  822. {0x79, 0x09}, {0xc8, 0x80}, {0x79, 0x02}, {0xc8, 0xc0},
  823. {0x79, 0x03}, {0xc8, 0x40}, {0x79, 0x05}, {0xc8, 0x30},
  824. {0x79, 0x26}, {0x62, 0x20}, {0x63, 0x00}, {0x64, 0x06},
  825. {0x65, 0x00}, {0x66, 0x05}, {0x94, 0x05}, {0x95, 0x0a},
  826. {0x17, 0x13}, {0x18, 0x01}, {0x19, 0x02}, {0x1a, 0x7a},
  827. {0x46, 0x59}, {0x47, 0x30}, {0x58, 0x9a}, {0x59, 0x84},
  828. {0x5a, 0x91}, {0x5b, 0x57}, {0x5c, 0x75}, {0x5d, 0x6d},
  829. {0x5e, 0x13}, {0x64, 0x07}, {0x94, 0x07}, {0x95, 0x0d},
  830. {0xa6, 0xdf}, {0xa7, 0xdf}, {0x48, 0x4d}, {0x51, 0x00},
  831. {0x6b, 0x0a}, {0x11, 0x80}, {0x2a, 0x00}, {0x2b, 0x00},
  832. {0x92, 0x00}, {0x93, 0x00}, {0x55, 0x0a}, {0x56, 0x60},
  833. {0x4f, 0x6e}, {0x50, 0x70}, {0x51, 0x00}, {0x52, 0x1d},
  834. {0x53, 0x56}, {0x54, 0x73}, {0x58, 0x9a}, {0x4f, 0x6e},
  835. {0x50, 0x70}, {0x51, 0x00}, {0x52, 0x1d}, {0x53, 0x56},
  836. {0x54, 0x73}, {0x58, 0x9a}, {0x3f, 0x01}, {0x7b, 0x03},
  837. {0x7c, 0x09}, {0x7d, 0x16}, {0x7e, 0x38}, {0x7f, 0x47},
  838. {0x80, 0x53}, {0x81, 0x5e}, {0x82, 0x6a}, {0x83, 0x74},
  839. {0x84, 0x80}, {0x85, 0x8c}, {0x86, 0x9b}, {0x87, 0xb2},
  840. {0x88, 0xcc}, {0x89, 0xe5}, {0x7a, 0x24}, {0x3b, 0x00},
  841. {0x9f, 0x76}, {0xa0, 0x65}, {0x13, 0xe2}, {0x6b, 0x0a},
  842. {0x11, 0x80}, {0x2a, 0x00}, {0x2b, 0x00}, {0x92, 0x00},
  843. {0x93, 0x00},
  844. };
  845. static struct i2c_reg_u8 ov9650_init[] = {
  846. {0x12, 0x80}, {0x00, 0x00}, {0x01, 0x78},
  847. {0x02, 0x78}, {0x03, 0x36}, {0x04, 0x03},
  848. {0x05, 0x00}, {0x06, 0x00}, {0x08, 0x00},
  849. {0x09, 0x01}, {0x0c, 0x00}, {0x0d, 0x00},
  850. {0x0e, 0xa0}, {0x0f, 0x52}, {0x10, 0x7c},
  851. {0x11, 0x80}, {0x12, 0x45}, {0x13, 0xc2},
  852. {0x14, 0x2e}, {0x15, 0x00}, {0x16, 0x07},
  853. {0x17, 0x24}, {0x18, 0xc5}, {0x19, 0x00},
  854. {0x1a, 0x3c}, {0x1b, 0x00}, {0x1e, 0x04},
  855. {0x1f, 0x00}, {0x24, 0x78}, {0x25, 0x68},
  856. {0x26, 0xd4}, {0x27, 0x80}, {0x28, 0x80},
  857. {0x29, 0x30}, {0x2a, 0x00}, {0x2b, 0x00},
  858. {0x2c, 0x80}, {0x2d, 0x00}, {0x2e, 0x00},
  859. {0x2f, 0x00}, {0x30, 0x08}, {0x31, 0x30},
  860. {0x32, 0x84}, {0x33, 0xe2}, {0x34, 0xbf},
  861. {0x35, 0x81}, {0x36, 0xf9}, {0x37, 0x00},
  862. {0x38, 0x93}, {0x39, 0x50}, {0x3a, 0x01},
  863. {0x3b, 0x01}, {0x3c, 0x73}, {0x3d, 0x19},
  864. {0x3e, 0x0b}, {0x3f, 0x80}, {0x40, 0xc1},
  865. {0x41, 0x00}, {0x42, 0x08}, {0x67, 0x80},
  866. {0x68, 0x80}, {0x69, 0x40}, {0x6a, 0x00},
  867. {0x6b, 0x0a}, {0x8b, 0x06}, {0x8c, 0x20},
  868. {0x8d, 0x00}, {0x8e, 0x00}, {0x8f, 0xdf},
  869. {0x92, 0x00}, {0x93, 0x00}, {0x94, 0x88},
  870. {0x95, 0x88}, {0x96, 0x04}, {0xa1, 0x00},
  871. {0xa5, 0x80}, {0xa8, 0x80}, {0xa9, 0xb8},
  872. {0xaa, 0x92}, {0xab, 0x0a},
  873. };
  874. static struct i2c_reg_u8 ov9655_init[] = {
  875. {0x12, 0x80}, {0x12, 0x01}, {0x0d, 0x00}, {0x0e, 0x61},
  876. {0x11, 0x80}, {0x13, 0xba}, {0x14, 0x2e}, {0x16, 0x24},
  877. {0x1e, 0x04}, {0x1e, 0x04}, {0x1e, 0x04}, {0x27, 0x08},
  878. {0x28, 0x08}, {0x29, 0x15}, {0x2c, 0x08}, {0x32, 0xbf},
  879. {0x34, 0x3d}, {0x35, 0x00}, {0x36, 0xf8}, {0x38, 0x12},
  880. {0x39, 0x57}, {0x3a, 0x00}, {0x3b, 0xcc}, {0x3c, 0x0c},
  881. {0x3d, 0x19}, {0x3e, 0x0c}, {0x3f, 0x01}, {0x41, 0x40},
  882. {0x42, 0x80}, {0x45, 0x46}, {0x46, 0x62}, {0x47, 0x2a},
  883. {0x48, 0x3c}, {0x4a, 0xf0}, {0x4b, 0xdc}, {0x4c, 0xdc},
  884. {0x4d, 0xdc}, {0x4e, 0xdc}, {0x69, 0x02}, {0x6c, 0x04},
  885. {0x6f, 0x9e}, {0x70, 0x05}, {0x71, 0x78}, {0x77, 0x02},
  886. {0x8a, 0x23}, {0x8c, 0x0d}, {0x90, 0x7e}, {0x91, 0x7c},
  887. {0x9f, 0x6e}, {0xa0, 0x6e}, {0xa5, 0x68}, {0xa6, 0x60},
  888. {0xa8, 0xc1}, {0xa9, 0xfa}, {0xaa, 0x92}, {0xab, 0x04},
  889. {0xac, 0x80}, {0xad, 0x80}, {0xae, 0x80}, {0xaf, 0x80},
  890. {0xb2, 0xf2}, {0xb3, 0x20}, {0xb5, 0x00}, {0xb6, 0xaf},
  891. {0xbb, 0xae}, {0xbc, 0x44}, {0xbd, 0x44}, {0xbe, 0x3b},
  892. {0xbf, 0x3a}, {0xc0, 0xe2}, {0xc1, 0xc8}, {0xc2, 0x01},
  893. {0xc4, 0x00}, {0xc6, 0x85}, {0xc7, 0x81}, {0xc9, 0xe0},
  894. {0xca, 0xe8}, {0xcc, 0xd8}, {0xcd, 0x93}, {0x12, 0x61},
  895. {0x36, 0xfa}, {0x8c, 0x8d}, {0xc0, 0xaa}, {0x69, 0x0a},
  896. {0x03, 0x12}, {0x17, 0x14}, {0x18, 0x00}, {0x19, 0x01},
  897. {0x1a, 0x3d}, {0x32, 0xbf}, {0x11, 0x80}, {0x2a, 0x10},
  898. {0x2b, 0x0a}, {0x92, 0x00}, {0x93, 0x00}, {0x1e, 0x04},
  899. {0x1e, 0x04}, {0x10, 0x7c}, {0x04, 0x03}, {0xa1, 0x00},
  900. {0x2d, 0x00}, {0x2e, 0x00}, {0x00, 0x00}, {0x01, 0x80},
  901. {0x02, 0x80}, {0x12, 0x61}, {0x36, 0xfa}, {0x8c, 0x8d},
  902. {0xc0, 0xaa}, {0x69, 0x0a}, {0x03, 0x12}, {0x17, 0x14},
  903. {0x18, 0x00}, {0x19, 0x01}, {0x1a, 0x3d}, {0x32, 0xbf},
  904. {0x11, 0x80}, {0x2a, 0x10}, {0x2b, 0x0a}, {0x92, 0x00},
  905. {0x93, 0x00}, {0x04, 0x01}, {0x10, 0x1f}, {0xa1, 0x00},
  906. {0x00, 0x0a}, {0xa1, 0x00}, {0x10, 0x5d}, {0x04, 0x03},
  907. {0x00, 0x01}, {0xa1, 0x00}, {0x10, 0x7c}, {0x04, 0x03},
  908. {0x00, 0x03}, {0x00, 0x0a}, {0x00, 0x10}, {0x00, 0x13},
  909. };
  910. static struct i2c_reg_u16 mt9v112_init[] = {
  911. {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0020},
  912. {0x34, 0xc019}, {0x0a, 0x0011}, {0x0b, 0x000b},
  913. {0x20, 0x0703}, {0x35, 0x2022}, {0xf0, 0x0001},
  914. {0x05, 0x0000}, {0x06, 0x340c}, {0x3b, 0x042a},
  915. {0x3c, 0x0400}, {0xf0, 0x0002}, {0x2e, 0x0c58},
  916. {0x5b, 0x0001}, {0xc8, 0x9f0b}, {0xf0, 0x0001},
  917. {0x9b, 0x5300}, {0xf0, 0x0000}, {0x2b, 0x0020},
  918. {0x2c, 0x002a}, {0x2d, 0x0032}, {0x2e, 0x0020},
  919. {0x09, 0x01dc}, {0x01, 0x000c}, {0x02, 0x0020},
  920. {0x03, 0x01e0}, {0x04, 0x0280}, {0x06, 0x000c},
  921. {0x05, 0x0098}, {0x20, 0x0703}, {0x09, 0x01f2},
  922. {0x2b, 0x00a0}, {0x2c, 0x00a0}, {0x2d, 0x00a0},
  923. {0x2e, 0x00a0}, {0x01, 0x000c}, {0x02, 0x0020},
  924. {0x03, 0x01e0}, {0x04, 0x0280}, {0x06, 0x000c},
  925. {0x05, 0x0098}, {0x09, 0x01c1}, {0x2b, 0x00ae},
  926. {0x2c, 0x00ae}, {0x2d, 0x00ae}, {0x2e, 0x00ae},
  927. };
  928. static struct i2c_reg_u16 mt9v111_init[] = {
  929. {0x01, 0x0004}, {0x0d, 0x0001}, {0x0d, 0x0000},
  930. {0x01, 0x0001}, {0x02, 0x0016}, {0x03, 0x01e1},
  931. {0x04, 0x0281}, {0x05, 0x0004}, {0x07, 0x3002},
  932. {0x21, 0x0000}, {0x25, 0x4024}, {0x26, 0xff03},
  933. {0x27, 0xff10}, {0x2b, 0x7828}, {0x2c, 0xb43c},
  934. {0x2d, 0xf0a0}, {0x2e, 0x0c64}, {0x2f, 0x0064},
  935. {0x67, 0x4010}, {0x06, 0x301e}, {0x08, 0x0480},
  936. {0x01, 0x0004}, {0x02, 0x0016}, {0x03, 0x01e6},
  937. {0x04, 0x0286}, {0x05, 0x0004}, {0x06, 0x0000},
  938. {0x07, 0x3002}, {0x08, 0x0008}, {0x0c, 0x0000},
  939. {0x0d, 0x0000}, {0x0e, 0x0000}, {0x0f, 0x0000},
  940. {0x10, 0x0000}, {0x11, 0x0000}, {0x12, 0x00b0},
  941. {0x13, 0x007c}, {0x14, 0x0000}, {0x15, 0x0000},
  942. {0x16, 0x0000}, {0x17, 0x0000}, {0x18, 0x0000},
  943. {0x19, 0x0000}, {0x1a, 0x0000}, {0x1b, 0x0000},
  944. {0x1c, 0x0000}, {0x1d, 0x0000}, {0x30, 0x0000},
  945. {0x30, 0x0005}, {0x31, 0x0000}, {0x02, 0x0016},
  946. {0x03, 0x01e1}, {0x04, 0x0281}, {0x05, 0x0004},
  947. {0x06, 0x0000}, {0x07, 0x3002}, {0x06, 0x002d},
  948. {0x05, 0x0004}, {0x09, 0x0064}, {0x2b, 0x00a0},
  949. {0x2c, 0x00a0}, {0x2d, 0x00a0}, {0x2e, 0x00a0},
  950. {0x02, 0x0016}, {0x03, 0x01e1}, {0x04, 0x0281},
  951. {0x05, 0x0004}, {0x06, 0x002d}, {0x07, 0x3002},
  952. {0x0e, 0x0008}, {0x06, 0x002d}, {0x05, 0x0004},
  953. };
  954. static struct i2c_reg_u16 mt9v011_init[] = {
  955. {0x07, 0x0002}, {0x0d, 0x0001}, {0x0d, 0x0000},
  956. {0x01, 0x0008}, {0x02, 0x0016}, {0x03, 0x01e1},
  957. {0x04, 0x0281}, {0x05, 0x0083}, {0x06, 0x0006},
  958. {0x0d, 0x0002}, {0x0a, 0x0000}, {0x0b, 0x0000},
  959. {0x0c, 0x0000}, {0x0d, 0x0000}, {0x0e, 0x0000},
  960. {0x0f, 0x0000}, {0x10, 0x0000}, {0x11, 0x0000},
  961. {0x12, 0x0000}, {0x13, 0x0000}, {0x14, 0x0000},
  962. {0x15, 0x0000}, {0x16, 0x0000}, {0x17, 0x0000},
  963. {0x18, 0x0000}, {0x19, 0x0000}, {0x1a, 0x0000},
  964. {0x1b, 0x0000}, {0x1c, 0x0000}, {0x1d, 0x0000},
  965. {0x32, 0x0000}, {0x20, 0x1101}, {0x21, 0x0000},
  966. {0x22, 0x0000}, {0x23, 0x0000}, {0x24, 0x0000},
  967. {0x25, 0x0000}, {0x26, 0x0000}, {0x27, 0x0024},
  968. {0x2f, 0xf7b0}, {0x30, 0x0005}, {0x31, 0x0000},
  969. {0x32, 0x0000}, {0x33, 0x0000}, {0x34, 0x0100},
  970. {0x3d, 0x068f}, {0x40, 0x01e0}, {0x41, 0x00d1},
  971. {0x44, 0x0082}, {0x5a, 0x0000}, {0x5b, 0x0000},
  972. {0x5c, 0x0000}, {0x5d, 0x0000}, {0x5e, 0x0000},
  973. {0x5f, 0xa31d}, {0x62, 0x0611}, {0x0a, 0x0000},
  974. {0x06, 0x0029}, {0x05, 0x0009}, {0x20, 0x1101},
  975. {0x20, 0x1101}, {0x09, 0x0064}, {0x07, 0x0003},
  976. {0x2b, 0x0033}, {0x2c, 0x00a0}, {0x2d, 0x00a0},
  977. {0x2e, 0x0033}, {0x07, 0x0002}, {0x06, 0x0000},
  978. {0x06, 0x0029}, {0x05, 0x0009},
  979. };
  980. static struct i2c_reg_u16 mt9m001_init[] = {
  981. {0x0d, 0x0001}, {0x0d, 0x0000}, {0x01, 0x000e},
  982. {0x02, 0x0014}, {0x03, 0x03c1}, {0x04, 0x0501},
  983. {0x05, 0x0083}, {0x06, 0x0006}, {0x0d, 0x0002},
  984. {0x0a, 0x0000}, {0x0c, 0x0000}, {0x11, 0x0000},
  985. {0x1e, 0x8000}, {0x5f, 0x8904}, {0x60, 0x0000},
  986. {0x61, 0x0000}, {0x62, 0x0498}, {0x63, 0x0000},
  987. {0x64, 0x0000}, {0x20, 0x111d}, {0x06, 0x00f2},
  988. {0x05, 0x0013}, {0x09, 0x10f2}, {0x07, 0x0003},
  989. {0x2b, 0x002a}, {0x2d, 0x002a}, {0x2c, 0x002a},
  990. {0x2e, 0x0029}, {0x07, 0x0002},
  991. };
  992. static struct i2c_reg_u16 mt9m111_init[] = {
  993. {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008},
  994. {0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300},
  995. {0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e},
  996. {0xf0, 0x0000},
  997. };
  998. static struct i2c_reg_u8 hv7131r_init[] = {
  999. {0x02, 0x08}, {0x02, 0x00}, {0x01, 0x08},
  1000. {0x02, 0x00}, {0x20, 0x00}, {0x21, 0xd0},
  1001. {0x22, 0x00}, {0x23, 0x09}, {0x01, 0x08},
  1002. {0x01, 0x08}, {0x01, 0x08}, {0x25, 0x07},
  1003. {0x26, 0xc3}, {0x27, 0x50}, {0x30, 0x62},
  1004. {0x31, 0x10}, {0x32, 0x06}, {0x33, 0x10},
  1005. {0x20, 0x00}, {0x21, 0xd0}, {0x22, 0x00},
  1006. {0x23, 0x09}, {0x01, 0x08},
  1007. };
  1008. static int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
  1009. {
  1010. struct usb_device *dev = gspca_dev->dev;
  1011. int result;
  1012. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  1013. 0x00,
  1014. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1015. reg,
  1016. 0x00,
  1017. gspca_dev->usb_buf,
  1018. length,
  1019. 500);
  1020. if (unlikely(result < 0 || result != length)) {
  1021. err("Read register failed 0x%02X", reg);
  1022. return -EIO;
  1023. }
  1024. return 0;
  1025. }
  1026. static int reg_w(struct gspca_dev *gspca_dev, u16 reg,
  1027. const u8 *buffer, int length)
  1028. {
  1029. struct usb_device *dev = gspca_dev->dev;
  1030. int result;
  1031. memcpy(gspca_dev->usb_buf, buffer, length);
  1032. result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  1033. 0x08,
  1034. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1035. reg,
  1036. 0x00,
  1037. gspca_dev->usb_buf,
  1038. length,
  1039. 500);
  1040. if (unlikely(result < 0 || result != length)) {
  1041. err("Write register failed index 0x%02X", reg);
  1042. return -EIO;
  1043. }
  1044. return 0;
  1045. }
  1046. static int reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value)
  1047. {
  1048. u8 data[1] = {value};
  1049. return reg_w(gspca_dev, reg, data, 1);
  1050. }
  1051. static int i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer)
  1052. {
  1053. int i;
  1054. reg_w(gspca_dev, 0x10c0, buffer, 8);
  1055. for (i = 0; i < 5; i++) {
  1056. reg_r(gspca_dev, 0x10c0, 1);
  1057. if (gspca_dev->usb_buf[0] & 0x04) {
  1058. if (gspca_dev->usb_buf[0] & 0x08)
  1059. return -EIO;
  1060. return 0;
  1061. }
  1062. msleep(1);
  1063. }
  1064. return -EIO;
  1065. }
  1066. static int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1067. {
  1068. struct sd *sd = (struct sd *) gspca_dev;
  1069. u8 row[8];
  1070. /*
  1071. * from the point of view of the bridge, the length
  1072. * includes the address
  1073. */
  1074. row[0] = 0x81 | (2 << 4);
  1075. row[1] = sd->i2c_addr;
  1076. row[2] = reg;
  1077. row[3] = val;
  1078. row[4] = 0x00;
  1079. row[5] = 0x00;
  1080. row[6] = 0x00;
  1081. row[7] = 0x10;
  1082. return i2c_w(gspca_dev, row);
  1083. }
  1084. static int i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val)
  1085. {
  1086. struct sd *sd = (struct sd *) gspca_dev;
  1087. u8 row[8];
  1088. /*
  1089. * from the point of view of the bridge, the length
  1090. * includes the address
  1091. */
  1092. row[0] = 0x81 | (3 << 4);
  1093. row[1] = sd->i2c_addr;
  1094. row[2] = reg;
  1095. row[3] = (val >> 8) & 0xff;
  1096. row[4] = val & 0xff;
  1097. row[5] = 0x00;
  1098. row[6] = 0x00;
  1099. row[7] = 0x10;
  1100. return i2c_w(gspca_dev, row);
  1101. }
  1102. static int i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
  1103. {
  1104. struct sd *sd = (struct sd *) gspca_dev;
  1105. u8 row[8];
  1106. row[0] = 0x81 | (1 << 4);
  1107. row[1] = sd->i2c_addr;
  1108. row[2] = reg;
  1109. row[3] = 0;
  1110. row[4] = 0;
  1111. row[5] = 0;
  1112. row[6] = 0;
  1113. row[7] = 0x10;
  1114. if (i2c_w(gspca_dev, row) < 0)
  1115. return -EIO;
  1116. row[0] = 0x81 | (1 << 4) | 0x02;
  1117. row[2] = 0;
  1118. if (i2c_w(gspca_dev, row) < 0)
  1119. return -EIO;
  1120. if (reg_r(gspca_dev, 0x10c2, 5) < 0)
  1121. return -EIO;
  1122. *val = gspca_dev->usb_buf[4];
  1123. return 0;
  1124. }
  1125. static int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
  1126. {
  1127. struct sd *sd = (struct sd *) gspca_dev;
  1128. u8 row[8];
  1129. row[0] = 0x81 | (1 << 4);
  1130. row[1] = sd->i2c_addr;
  1131. row[2] = reg;
  1132. row[3] = 0;
  1133. row[4] = 0;
  1134. row[5] = 0;
  1135. row[6] = 0;
  1136. row[7] = 0x10;
  1137. if (i2c_w(gspca_dev, row) < 0)
  1138. return -EIO;
  1139. row[0] = 0x81 | (2 << 4) | 0x02;
  1140. row[2] = 0;
  1141. if (i2c_w(gspca_dev, row) < 0)
  1142. return -EIO;
  1143. if (reg_r(gspca_dev, 0x10c2, 5) < 0)
  1144. return -EIO;
  1145. *val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1146. return 0;
  1147. }
  1148. static int ov9650_init_sensor(struct gspca_dev *gspca_dev)
  1149. {
  1150. int i;
  1151. struct sd *sd = (struct sd *) gspca_dev;
  1152. for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) {
  1153. if (i2c_w1(gspca_dev, ov9650_init[i].reg,
  1154. ov9650_init[i].val) < 0) {
  1155. err("OV9650 sensor initialization failed");
  1156. return -ENODEV;
  1157. }
  1158. }
  1159. sd->hstart = 1;
  1160. sd->vstart = 7;
  1161. return 0;
  1162. }
  1163. static int ov9655_init_sensor(struct gspca_dev *gspca_dev)
  1164. {
  1165. int i;
  1166. struct sd *sd = (struct sd *) gspca_dev;
  1167. for (i = 0; i < ARRAY_SIZE(ov9655_init); i++) {
  1168. if (i2c_w1(gspca_dev, ov9655_init[i].reg,
  1169. ov9655_init[i].val) < 0) {
  1170. err("OV9655 sensor initialization failed");
  1171. return -ENODEV;
  1172. }
  1173. }
  1174. /* disable hflip and vflip */
  1175. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1176. sd->hstart = 0;
  1177. sd->vstart = 7;
  1178. return 0;
  1179. }
  1180. static int soi968_init_sensor(struct gspca_dev *gspca_dev)
  1181. {
  1182. int i;
  1183. struct sd *sd = (struct sd *) gspca_dev;
  1184. for (i = 0; i < ARRAY_SIZE(soi968_init); i++) {
  1185. if (i2c_w1(gspca_dev, soi968_init[i].reg,
  1186. soi968_init[i].val) < 0) {
  1187. err("SOI968 sensor initialization failed");
  1188. return -ENODEV;
  1189. }
  1190. }
  1191. /* disable hflip and vflip */
  1192. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << EXPOSURE_IDX);
  1193. sd->hstart = 60;
  1194. sd->vstart = 11;
  1195. return 0;
  1196. }
  1197. static int ov7660_init_sensor(struct gspca_dev *gspca_dev)
  1198. {
  1199. int i;
  1200. struct sd *sd = (struct sd *) gspca_dev;
  1201. for (i = 0; i < ARRAY_SIZE(ov7660_init); i++) {
  1202. if (i2c_w1(gspca_dev, ov7660_init[i].reg,
  1203. ov7660_init[i].val) < 0) {
  1204. err("OV7660 sensor initialization failed");
  1205. return -ENODEV;
  1206. }
  1207. }
  1208. /* disable hflip and vflip */
  1209. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1210. sd->hstart = 1;
  1211. sd->vstart = 1;
  1212. return 0;
  1213. }
  1214. static int ov7670_init_sensor(struct gspca_dev *gspca_dev)
  1215. {
  1216. int i;
  1217. struct sd *sd = (struct sd *) gspca_dev;
  1218. for (i = 0; i < ARRAY_SIZE(ov7670_init); i++) {
  1219. if (i2c_w1(gspca_dev, ov7670_init[i].reg,
  1220. ov7670_init[i].val) < 0) {
  1221. err("OV7670 sensor initialization failed");
  1222. return -ENODEV;
  1223. }
  1224. }
  1225. /* disable hflip and vflip */
  1226. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1227. sd->hstart = 0;
  1228. sd->vstart = 1;
  1229. return 0;
  1230. }
  1231. static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
  1232. {
  1233. struct sd *sd = (struct sd *) gspca_dev;
  1234. int i;
  1235. u16 value;
  1236. int ret;
  1237. sd->i2c_addr = 0x5d;
  1238. ret = i2c_r2(gspca_dev, 0xff, &value);
  1239. if ((ret == 0) && (value == 0x8243)) {
  1240. for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) {
  1241. if (i2c_w2(gspca_dev, mt9v011_init[i].reg,
  1242. mt9v011_init[i].val) < 0) {
  1243. err("MT9V011 sensor initialization failed");
  1244. return -ENODEV;
  1245. }
  1246. }
  1247. sd->hstart = 2;
  1248. sd->vstart = 2;
  1249. sd->sensor = SENSOR_MT9V011;
  1250. info("MT9V011 sensor detected");
  1251. return 0;
  1252. }
  1253. sd->i2c_addr = 0x5c;
  1254. i2c_w2(gspca_dev, 0x01, 0x0004);
  1255. ret = i2c_r2(gspca_dev, 0xff, &value);
  1256. if ((ret == 0) && (value == 0x823a)) {
  1257. for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) {
  1258. if (i2c_w2(gspca_dev, mt9v111_init[i].reg,
  1259. mt9v111_init[i].val) < 0) {
  1260. err("MT9V111 sensor initialization failed");
  1261. return -ENODEV;
  1262. }
  1263. }
  1264. sd->hstart = 2;
  1265. sd->vstart = 2;
  1266. sd->sensor = SENSOR_MT9V111;
  1267. info("MT9V111 sensor detected");
  1268. return 0;
  1269. }
  1270. sd->i2c_addr = 0x5d;
  1271. ret = i2c_w2(gspca_dev, 0xf0, 0x0000);
  1272. if (ret < 0) {
  1273. sd->i2c_addr = 0x48;
  1274. i2c_w2(gspca_dev, 0xf0, 0x0000);
  1275. }
  1276. ret = i2c_r2(gspca_dev, 0x00, &value);
  1277. if ((ret == 0) && (value == 0x1229)) {
  1278. for (i = 0; i < ARRAY_SIZE(mt9v112_init); i++) {
  1279. if (i2c_w2(gspca_dev, mt9v112_init[i].reg,
  1280. mt9v112_init[i].val) < 0) {
  1281. err("MT9V112 sensor initialization failed");
  1282. return -ENODEV;
  1283. }
  1284. }
  1285. sd->hstart = 6;
  1286. sd->vstart = 2;
  1287. sd->sensor = SENSOR_MT9V112;
  1288. info("MT9V112 sensor detected");
  1289. return 0;
  1290. }
  1291. return -ENODEV;
  1292. }
  1293. static int mt9m111_init_sensor(struct gspca_dev *gspca_dev)
  1294. {
  1295. struct sd *sd = (struct sd *) gspca_dev;
  1296. int i;
  1297. for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) {
  1298. if (i2c_w2(gspca_dev, mt9m111_init[i].reg,
  1299. mt9m111_init[i].val) < 0) {
  1300. err("MT9M111 sensor initialization failed");
  1301. return -ENODEV;
  1302. }
  1303. }
  1304. gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX) | (1 << GAIN_IDX);
  1305. sd->hstart = 0;
  1306. sd->vstart = 2;
  1307. return 0;
  1308. }
  1309. static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
  1310. {
  1311. struct sd *sd = (struct sd *) gspca_dev;
  1312. int i;
  1313. for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
  1314. if (i2c_w2(gspca_dev, mt9m001_init[i].reg,
  1315. mt9m001_init[i].val) < 0) {
  1316. err("MT9M001 sensor initialization failed");
  1317. return -ENODEV;
  1318. }
  1319. }
  1320. /* disable hflip and vflip */
  1321. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1322. sd->hstart = 2;
  1323. sd->vstart = 2;
  1324. return 0;
  1325. }
  1326. static int hv7131r_init_sensor(struct gspca_dev *gspca_dev)
  1327. {
  1328. int i;
  1329. struct sd *sd = (struct sd *) gspca_dev;
  1330. for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) {
  1331. if (i2c_w1(gspca_dev, hv7131r_init[i].reg,
  1332. hv7131r_init[i].val) < 0) {
  1333. err("HV7131R Sensor initialization failed");
  1334. return -ENODEV;
  1335. }
  1336. }
  1337. sd->hstart = 0;
  1338. sd->vstart = 1;
  1339. return 0;
  1340. }
  1341. static int set_cmatrix(struct gspca_dev *gspca_dev)
  1342. {
  1343. struct sd *sd = (struct sd *) gspca_dev;
  1344. s32 hue_coord, hue_index = 180 + sd->hue;
  1345. u8 cmatrix[21];
  1346. memset(cmatrix, 0, sizeof cmatrix);
  1347. cmatrix[2] = (sd->contrast * 0x25 / 0x100) + 0x26;
  1348. cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25;
  1349. cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25;
  1350. cmatrix[18] = sd->brightness - 0x80;
  1351. hue_coord = (hsv_red_x[hue_index] * sd->saturation) >> 8;
  1352. cmatrix[6] = hue_coord;
  1353. cmatrix[7] = (hue_coord >> 8) & 0x0f;
  1354. hue_coord = (hsv_red_y[hue_index] * sd->saturation) >> 8;
  1355. cmatrix[8] = hue_coord;
  1356. cmatrix[9] = (hue_coord >> 8) & 0x0f;
  1357. hue_coord = (hsv_green_x[hue_index] * sd->saturation) >> 8;
  1358. cmatrix[10] = hue_coord;
  1359. cmatrix[11] = (hue_coord >> 8) & 0x0f;
  1360. hue_coord = (hsv_green_y[hue_index] * sd->saturation) >> 8;
  1361. cmatrix[12] = hue_coord;
  1362. cmatrix[13] = (hue_coord >> 8) & 0x0f;
  1363. hue_coord = (hsv_blue_x[hue_index] * sd->saturation) >> 8;
  1364. cmatrix[14] = hue_coord;
  1365. cmatrix[15] = (hue_coord >> 8) & 0x0f;
  1366. hue_coord = (hsv_blue_y[hue_index] * sd->saturation) >> 8;
  1367. cmatrix[16] = hue_coord;
  1368. cmatrix[17] = (hue_coord >> 8) & 0x0f;
  1369. return reg_w(gspca_dev, 0x10e1, cmatrix, 21);
  1370. }
  1371. static int set_gamma(struct gspca_dev *gspca_dev)
  1372. {
  1373. struct sd *sd = (struct sd *) gspca_dev;
  1374. u8 gamma[17];
  1375. u8 gval = sd->gamma * 0xb8 / 0x100;
  1376. gamma[0] = 0x0a;
  1377. gamma[1] = 0x13 + (gval * (0xcb - 0x13) / 0xb8);
  1378. gamma[2] = 0x25 + (gval * (0xee - 0x25) / 0xb8);
  1379. gamma[3] = 0x37 + (gval * (0xfa - 0x37) / 0xb8);
  1380. gamma[4] = 0x45 + (gval * (0xfc - 0x45) / 0xb8);
  1381. gamma[5] = 0x55 + (gval * (0xfb - 0x55) / 0xb8);
  1382. gamma[6] = 0x65 + (gval * (0xfc - 0x65) / 0xb8);
  1383. gamma[7] = 0x74 + (gval * (0xfd - 0x74) / 0xb8);
  1384. gamma[8] = 0x83 + (gval * (0xfe - 0x83) / 0xb8);
  1385. gamma[9] = 0x92 + (gval * (0xfc - 0x92) / 0xb8);
  1386. gamma[10] = 0xa1 + (gval * (0xfc - 0xa1) / 0xb8);
  1387. gamma[11] = 0xb0 + (gval * (0xfc - 0xb0) / 0xb8);
  1388. gamma[12] = 0xbf + (gval * (0xfb - 0xbf) / 0xb8);
  1389. gamma[13] = 0xce + (gval * (0xfb - 0xce) / 0xb8);
  1390. gamma[14] = 0xdf + (gval * (0xfd - 0xdf) / 0xb8);
  1391. gamma[15] = 0xea + (gval * (0xf9 - 0xea) / 0xb8);
  1392. gamma[16] = 0xf5;
  1393. return reg_w(gspca_dev, 0x1190, gamma, 17);
  1394. }
  1395. static int set_redblue(struct gspca_dev *gspca_dev)
  1396. {
  1397. struct sd *sd = (struct sd *) gspca_dev;
  1398. reg_w1(gspca_dev, 0x118c, sd->red);
  1399. reg_w1(gspca_dev, 0x118f, sd->blue);
  1400. return 0;
  1401. }
  1402. static int set_hvflip(struct gspca_dev *gspca_dev)
  1403. {
  1404. u8 value, tslb;
  1405. u16 value2;
  1406. struct sd *sd = (struct sd *) gspca_dev;
  1407. switch (sd->sensor) {
  1408. case SENSOR_OV9650:
  1409. i2c_r1(gspca_dev, 0x1e, &value);
  1410. value &= ~0x30;
  1411. tslb = 0x01;
  1412. if (sd->hflip)
  1413. value |= 0x20;
  1414. if (sd->vflip) {
  1415. value |= 0x10;
  1416. tslb = 0x49;
  1417. }
  1418. i2c_w1(gspca_dev, 0x1e, value);
  1419. i2c_w1(gspca_dev, 0x3a, tslb);
  1420. break;
  1421. case SENSOR_MT9V111:
  1422. case SENSOR_MT9V011:
  1423. i2c_r2(gspca_dev, 0x20, &value2);
  1424. value2 &= ~0xc0a0;
  1425. if (sd->hflip)
  1426. value2 |= 0x8080;
  1427. if (sd->vflip)
  1428. value2 |= 0x4020;
  1429. i2c_w2(gspca_dev, 0x20, value2);
  1430. break;
  1431. case SENSOR_MT9M111:
  1432. case SENSOR_MT9V112:
  1433. i2c_r2(gspca_dev, 0x20, &value2);
  1434. value2 &= ~0x0003;
  1435. if (sd->hflip)
  1436. value2 |= 0x0002;
  1437. if (sd->vflip)
  1438. value2 |= 0x0001;
  1439. i2c_w2(gspca_dev, 0x20, value2);
  1440. break;
  1441. case SENSOR_HV7131R:
  1442. i2c_r1(gspca_dev, 0x01, &value);
  1443. value &= ~0x03;
  1444. if (sd->vflip)
  1445. value |= 0x01;
  1446. if (sd->hflip)
  1447. value |= 0x02;
  1448. i2c_w1(gspca_dev, 0x01, value);
  1449. break;
  1450. }
  1451. return 0;
  1452. }
  1453. static int set_exposure(struct gspca_dev *gspca_dev)
  1454. {
  1455. struct sd *sd = (struct sd *) gspca_dev;
  1456. u8 exp[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e};
  1457. switch (sd->sensor) {
  1458. case SENSOR_OV7660:
  1459. case SENSOR_OV7670:
  1460. case SENSOR_OV9655:
  1461. case SENSOR_OV9650:
  1462. exp[0] |= (3 << 4);
  1463. exp[2] = 0x2d;
  1464. exp[3] = sd->exposure & 0xff;
  1465. exp[4] = sd->exposure >> 8;
  1466. break;
  1467. case SENSOR_MT9M001:
  1468. case SENSOR_MT9V112:
  1469. case SENSOR_MT9V111:
  1470. case SENSOR_MT9V011:
  1471. exp[0] |= (3 << 4);
  1472. exp[2] = 0x09;
  1473. exp[3] = sd->exposure >> 8;
  1474. exp[4] = sd->exposure & 0xff;
  1475. break;
  1476. case SENSOR_HV7131R:
  1477. exp[0] |= (4 << 4);
  1478. exp[2] = 0x25;
  1479. exp[3] = (sd->exposure >> 5) & 0xff;
  1480. exp[4] = (sd->exposure << 3) & 0xff;
  1481. exp[5] = 0;
  1482. break;
  1483. default:
  1484. return 0;
  1485. }
  1486. i2c_w(gspca_dev, exp);
  1487. return 0;
  1488. }
  1489. static int set_gain(struct gspca_dev *gspca_dev)
  1490. {
  1491. struct sd *sd = (struct sd *) gspca_dev;
  1492. u8 gain[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d};
  1493. switch (sd->sensor) {
  1494. case SENSOR_OV7660:
  1495. case SENSOR_OV7670:
  1496. case SENSOR_SOI968:
  1497. case SENSOR_OV9655:
  1498. case SENSOR_OV9650:
  1499. gain[0] |= (2 << 4);
  1500. gain[3] = ov_gain[sd->gain];
  1501. break;
  1502. case SENSOR_MT9V011:
  1503. case SENSOR_MT9V111:
  1504. gain[0] |= (3 << 4);
  1505. gain[2] = 0x35;
  1506. gain[3] = micron1_gain[sd->gain] >> 8;
  1507. gain[4] = micron1_gain[sd->gain] & 0xff;
  1508. break;
  1509. case SENSOR_MT9V112:
  1510. gain[0] |= (3 << 4);
  1511. gain[2] = 0x2f;
  1512. gain[3] = micron1_gain[sd->gain] >> 8;
  1513. gain[4] = micron1_gain[sd->gain] & 0xff;
  1514. break;
  1515. case SENSOR_MT9M001:
  1516. gain[0] |= (3 << 4);
  1517. gain[2] = 0x2f;
  1518. gain[3] = micron2_gain[sd->gain] >> 8;
  1519. gain[4] = micron2_gain[sd->gain] & 0xff;
  1520. break;
  1521. case SENSOR_HV7131R:
  1522. gain[0] |= (2 << 4);
  1523. gain[2] = 0x30;
  1524. gain[3] = hv7131r_gain[sd->gain];
  1525. break;
  1526. default:
  1527. return 0;
  1528. }
  1529. i2c_w(gspca_dev, gain);
  1530. return 0;
  1531. }
  1532. static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val)
  1533. {
  1534. struct sd *sd = (struct sd *) gspca_dev;
  1535. sd->brightness = val;
  1536. if (gspca_dev->streaming)
  1537. return set_cmatrix(gspca_dev);
  1538. return 0;
  1539. }
  1540. static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val)
  1541. {
  1542. struct sd *sd = (struct sd *) gspca_dev;
  1543. *val = sd->brightness;
  1544. return 0;
  1545. }
  1546. static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val)
  1547. {
  1548. struct sd *sd = (struct sd *) gspca_dev;
  1549. sd->contrast = val;
  1550. if (gspca_dev->streaming)
  1551. return set_cmatrix(gspca_dev);
  1552. return 0;
  1553. }
  1554. static int sd_getcontrast(struct gspca_dev *gspca_dev, s32 *val)
  1555. {
  1556. struct sd *sd = (struct sd *) gspca_dev;
  1557. *val = sd->contrast;
  1558. return 0;
  1559. }
  1560. static int sd_setsaturation(struct gspca_dev *gspca_dev, s32 val)
  1561. {
  1562. struct sd *sd = (struct sd *) gspca_dev;
  1563. sd->saturation = val;
  1564. if (gspca_dev->streaming)
  1565. return set_cmatrix(gspca_dev);
  1566. return 0;
  1567. }
  1568. static int sd_getsaturation(struct gspca_dev *gspca_dev, s32 *val)
  1569. {
  1570. struct sd *sd = (struct sd *) gspca_dev;
  1571. *val = sd->saturation;
  1572. return 0;
  1573. }
  1574. static int sd_sethue(struct gspca_dev *gspca_dev, s32 val)
  1575. {
  1576. struct sd *sd = (struct sd *) gspca_dev;
  1577. sd->hue = val;
  1578. if (gspca_dev->streaming)
  1579. return set_cmatrix(gspca_dev);
  1580. return 0;
  1581. }
  1582. static int sd_gethue(struct gspca_dev *gspca_dev, s32 *val)
  1583. {
  1584. struct sd *sd = (struct sd *) gspca_dev;
  1585. *val = sd->hue;
  1586. return 0;
  1587. }
  1588. static int sd_setgamma(struct gspca_dev *gspca_dev, s32 val)
  1589. {
  1590. struct sd *sd = (struct sd *) gspca_dev;
  1591. sd->gamma = val;
  1592. if (gspca_dev->streaming)
  1593. return set_gamma(gspca_dev);
  1594. return 0;
  1595. }
  1596. static int sd_getgamma(struct gspca_dev *gspca_dev, s32 *val)
  1597. {
  1598. struct sd *sd = (struct sd *) gspca_dev;
  1599. *val = sd->gamma;
  1600. return 0;
  1601. }
  1602. static int sd_setredbalance(struct gspca_dev *gspca_dev, s32 val)
  1603. {
  1604. struct sd *sd = (struct sd *) gspca_dev;
  1605. sd->red = val;
  1606. if (gspca_dev->streaming)
  1607. return set_redblue(gspca_dev);
  1608. return 0;
  1609. }
  1610. static int sd_getredbalance(struct gspca_dev *gspca_dev, s32 *val)
  1611. {
  1612. struct sd *sd = (struct sd *) gspca_dev;
  1613. *val = sd->red;
  1614. return 0;
  1615. }
  1616. static int sd_setbluebalance(struct gspca_dev *gspca_dev, s32 val)
  1617. {
  1618. struct sd *sd = (struct sd *) gspca_dev;
  1619. sd->blue = val;
  1620. if (gspca_dev->streaming)
  1621. return set_redblue(gspca_dev);
  1622. return 0;
  1623. }
  1624. static int sd_getbluebalance(struct gspca_dev *gspca_dev, s32 *val)
  1625. {
  1626. struct sd *sd = (struct sd *) gspca_dev;
  1627. *val = sd->blue;
  1628. return 0;
  1629. }
  1630. static int sd_sethflip(struct gspca_dev *gspca_dev, s32 val)
  1631. {
  1632. struct sd *sd = (struct sd *) gspca_dev;
  1633. sd->hflip = val;
  1634. if (gspca_dev->streaming)
  1635. return set_hvflip(gspca_dev);
  1636. return 0;
  1637. }
  1638. static int sd_gethflip(struct gspca_dev *gspca_dev, s32 *val)
  1639. {
  1640. struct sd *sd = (struct sd *) gspca_dev;
  1641. *val = sd->hflip;
  1642. return 0;
  1643. }
  1644. static int sd_setvflip(struct gspca_dev *gspca_dev, s32 val)
  1645. {
  1646. struct sd *sd = (struct sd *) gspca_dev;
  1647. sd->vflip = val;
  1648. if (gspca_dev->streaming)
  1649. return set_hvflip(gspca_dev);
  1650. return 0;
  1651. }
  1652. static int sd_getvflip(struct gspca_dev *gspca_dev, s32 *val)
  1653. {
  1654. struct sd *sd = (struct sd *) gspca_dev;
  1655. *val = sd->vflip;
  1656. return 0;
  1657. }
  1658. static int sd_setexposure(struct gspca_dev *gspca_dev, s32 val)
  1659. {
  1660. struct sd *sd = (struct sd *) gspca_dev;
  1661. sd->exposure = val;
  1662. if (gspca_dev->streaming)
  1663. return set_exposure(gspca_dev);
  1664. return 0;
  1665. }
  1666. static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val)
  1667. {
  1668. struct sd *sd = (struct sd *) gspca_dev;
  1669. *val = sd->exposure;
  1670. return 0;
  1671. }
  1672. static int sd_setgain(struct gspca_dev *gspca_dev, s32 val)
  1673. {
  1674. struct sd *sd = (struct sd *) gspca_dev;
  1675. sd->gain = val;
  1676. if (gspca_dev->streaming)
  1677. return set_gain(gspca_dev);
  1678. return 0;
  1679. }
  1680. static int sd_getgain(struct gspca_dev *gspca_dev, s32 *val)
  1681. {
  1682. struct sd *sd = (struct sd *) gspca_dev;
  1683. *val = sd->gain;
  1684. return 0;
  1685. }
  1686. static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val)
  1687. {
  1688. struct sd *sd = (struct sd *) gspca_dev;
  1689. sd->auto_exposure = val;
  1690. return 0;
  1691. }
  1692. static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val)
  1693. {
  1694. struct sd *sd = (struct sd *) gspca_dev;
  1695. *val = sd->auto_exposure;
  1696. return 0;
  1697. }
  1698. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1699. static int sd_dbg_g_register(struct gspca_dev *gspca_dev,
  1700. struct v4l2_dbg_register *reg)
  1701. {
  1702. struct sd *sd = (struct sd *) gspca_dev;
  1703. switch (reg->match.type) {
  1704. case V4L2_CHIP_MATCH_HOST:
  1705. if (reg->match.addr != 0)
  1706. return -EINVAL;
  1707. if (reg->reg < 0x1000 || reg->reg > 0x11ff)
  1708. return -EINVAL;
  1709. if (reg_r(gspca_dev, reg->reg, 1) < 0)
  1710. return -EINVAL;
  1711. reg->val = gspca_dev->usb_buf[0];
  1712. return 0;
  1713. case V4L2_CHIP_MATCH_I2C_ADDR:
  1714. if (reg->match.addr != sd->i2c_addr)
  1715. return -EINVAL;
  1716. if (sd->sensor >= SENSOR_MT9V011 &&
  1717. sd->sensor <= SENSOR_MT9M111) {
  1718. if (i2c_r2(gspca_dev, reg->reg, (u16 *)&reg->val) < 0)
  1719. return -EINVAL;
  1720. } else {
  1721. if (i2c_r1(gspca_dev, reg->reg, (u8 *)&reg->val) < 0)
  1722. return -EINVAL;
  1723. }
  1724. return 0;
  1725. }
  1726. return -EINVAL;
  1727. }
  1728. static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
  1729. struct v4l2_dbg_register *reg)
  1730. {
  1731. struct sd *sd = (struct sd *) gspca_dev;
  1732. switch (reg->match.type) {
  1733. case V4L2_CHIP_MATCH_HOST:
  1734. if (reg->match.addr != 0)
  1735. return -EINVAL;
  1736. if (reg->reg < 0x1000 || reg->reg > 0x11ff)
  1737. return -EINVAL;
  1738. if (reg_w1(gspca_dev, reg->reg, reg->val) < 0)
  1739. return -EINVAL;
  1740. return 0;
  1741. case V4L2_CHIP_MATCH_I2C_ADDR:
  1742. if (reg->match.addr != sd->i2c_addr)
  1743. return -EINVAL;
  1744. if (sd->sensor >= SENSOR_MT9V011 &&
  1745. sd->sensor <= SENSOR_MT9M111) {
  1746. if (i2c_w2(gspca_dev, reg->reg, reg->val) < 0)
  1747. return -EINVAL;
  1748. } else {
  1749. if (i2c_w1(gspca_dev, reg->reg, reg->val) < 0)
  1750. return -EINVAL;
  1751. }
  1752. return 0;
  1753. }
  1754. return -EINVAL;
  1755. }
  1756. #endif
  1757. static int sd_chip_ident(struct gspca_dev *gspca_dev,
  1758. struct v4l2_dbg_chip_ident *chip)
  1759. {
  1760. struct sd *sd = (struct sd *) gspca_dev;
  1761. switch (chip->match.type) {
  1762. case V4L2_CHIP_MATCH_HOST:
  1763. if (chip->match.addr != 0)
  1764. return -EINVAL;
  1765. chip->revision = 0;
  1766. chip->ident = V4L2_IDENT_SN9C20X;
  1767. return 0;
  1768. case V4L2_CHIP_MATCH_I2C_ADDR:
  1769. if (chip->match.addr != sd->i2c_addr)
  1770. return -EINVAL;
  1771. chip->revision = 0;
  1772. chip->ident = i2c_ident[sd->sensor];
  1773. return 0;
  1774. }
  1775. return -EINVAL;
  1776. }
  1777. static int sd_config(struct gspca_dev *gspca_dev,
  1778. const struct usb_device_id *id)
  1779. {
  1780. struct sd *sd = (struct sd *) gspca_dev;
  1781. struct cam *cam;
  1782. cam = &gspca_dev->cam;
  1783. sd->sensor = (id->driver_info >> 8) & 0xff;
  1784. sd->i2c_addr = id->driver_info & 0xff;
  1785. sd->flags = (id->driver_info >> 16) & 0xff;
  1786. switch (sd->sensor) {
  1787. case SENSOR_MT9M111:
  1788. case SENSOR_OV9650:
  1789. case SENSOR_SOI968:
  1790. cam->cam_mode = sxga_mode;
  1791. cam->nmodes = ARRAY_SIZE(sxga_mode);
  1792. break;
  1793. default:
  1794. cam->cam_mode = vga_mode;
  1795. cam->nmodes = ARRAY_SIZE(vga_mode);
  1796. break;
  1797. }
  1798. sd->old_step = 0;
  1799. sd->older_step = 0;
  1800. sd->exposure_step = 16;
  1801. sd->brightness = BRIGHTNESS_DEFAULT;
  1802. sd->contrast = CONTRAST_DEFAULT;
  1803. sd->saturation = SATURATION_DEFAULT;
  1804. sd->hue = HUE_DEFAULT;
  1805. sd->gamma = GAMMA_DEFAULT;
  1806. sd->red = RED_DEFAULT;
  1807. sd->blue = BLUE_DEFAULT;
  1808. sd->hflip = HFLIP_DEFAULT;
  1809. sd->vflip = VFLIP_DEFAULT;
  1810. sd->exposure = EXPOSURE_DEFAULT;
  1811. sd->gain = GAIN_DEFAULT;
  1812. sd->auto_exposure = AUTO_EXPOSURE_DEFAULT;
  1813. sd->quality = 95;
  1814. return 0;
  1815. }
  1816. static int sd_init(struct gspca_dev *gspca_dev)
  1817. {
  1818. struct sd *sd = (struct sd *) gspca_dev;
  1819. int i;
  1820. u8 value;
  1821. u8 i2c_init[9] =
  1822. {0x80, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03};
  1823. for (i = 0; i < ARRAY_SIZE(bridge_init); i++) {
  1824. value = bridge_init[i][1];
  1825. if (reg_w(gspca_dev, bridge_init[i][0], &value, 1) < 0) {
  1826. err("Device initialization failed");
  1827. return -ENODEV;
  1828. }
  1829. }
  1830. if (reg_w(gspca_dev, 0x10c0, i2c_init, 9) < 0) {
  1831. err("Device initialization failed");
  1832. return -ENODEV;
  1833. }
  1834. switch (sd->sensor) {
  1835. case SENSOR_OV9650:
  1836. if (ov9650_init_sensor(gspca_dev) < 0)
  1837. return -ENODEV;
  1838. info("OV9650 sensor detected");
  1839. break;
  1840. case SENSOR_OV9655:
  1841. if (ov9655_init_sensor(gspca_dev) < 0)
  1842. return -ENODEV;
  1843. info("OV9655 sensor detected");
  1844. break;
  1845. case SENSOR_SOI968:
  1846. if (soi968_init_sensor(gspca_dev) < 0)
  1847. return -ENODEV;
  1848. info("SOI968 sensor detected");
  1849. break;
  1850. case SENSOR_OV7660:
  1851. if (ov7660_init_sensor(gspca_dev) < 0)
  1852. return -ENODEV;
  1853. info("OV7660 sensor detected");
  1854. break;
  1855. case SENSOR_OV7670:
  1856. if (ov7670_init_sensor(gspca_dev) < 0)
  1857. return -ENODEV;
  1858. info("OV7670 sensor detected");
  1859. break;
  1860. case SENSOR_MT9VPRB:
  1861. if (mt9v_init_sensor(gspca_dev) < 0)
  1862. return -ENODEV;
  1863. break;
  1864. case SENSOR_MT9M111:
  1865. if (mt9m111_init_sensor(gspca_dev) < 0)
  1866. return -ENODEV;
  1867. info("MT9M111 sensor detected");
  1868. break;
  1869. case SENSOR_MT9M001:
  1870. if (mt9m001_init_sensor(gspca_dev) < 0)
  1871. return -ENODEV;
  1872. info("MT9M001 sensor detected");
  1873. break;
  1874. case SENSOR_HV7131R:
  1875. if (hv7131r_init_sensor(gspca_dev) < 0)
  1876. return -ENODEV;
  1877. info("HV7131R sensor detected");
  1878. break;
  1879. default:
  1880. info("Unsupported Sensor");
  1881. return -ENODEV;
  1882. }
  1883. return 0;
  1884. }
  1885. static void configure_sensor_output(struct gspca_dev *gspca_dev, int mode)
  1886. {
  1887. struct sd *sd = (struct sd *) gspca_dev;
  1888. u8 value;
  1889. switch (sd->sensor) {
  1890. case SENSOR_SOI968:
  1891. if (mode & MODE_SXGA) {
  1892. i2c_w1(gspca_dev, 0x17, 0x1d);
  1893. i2c_w1(gspca_dev, 0x18, 0xbd);
  1894. i2c_w1(gspca_dev, 0x19, 0x01);
  1895. i2c_w1(gspca_dev, 0x1a, 0x81);
  1896. i2c_w1(gspca_dev, 0x12, 0x00);
  1897. sd->hstart = 140;
  1898. sd->vstart = 19;
  1899. } else {
  1900. i2c_w1(gspca_dev, 0x17, 0x13);
  1901. i2c_w1(gspca_dev, 0x18, 0x63);
  1902. i2c_w1(gspca_dev, 0x19, 0x01);
  1903. i2c_w1(gspca_dev, 0x1a, 0x79);
  1904. i2c_w1(gspca_dev, 0x12, 0x40);
  1905. sd->hstart = 60;
  1906. sd->vstart = 11;
  1907. }
  1908. break;
  1909. case SENSOR_OV9650:
  1910. if (mode & MODE_SXGA) {
  1911. i2c_w1(gspca_dev, 0x17, 0x1b);
  1912. i2c_w1(gspca_dev, 0x18, 0xbc);
  1913. i2c_w1(gspca_dev, 0x19, 0x01);
  1914. i2c_w1(gspca_dev, 0x1a, 0x82);
  1915. i2c_r1(gspca_dev, 0x12, &value);
  1916. i2c_w1(gspca_dev, 0x12, value & 0x07);
  1917. } else {
  1918. i2c_w1(gspca_dev, 0x17, 0x24);
  1919. i2c_w1(gspca_dev, 0x18, 0xc5);
  1920. i2c_w1(gspca_dev, 0x19, 0x00);
  1921. i2c_w1(gspca_dev, 0x1a, 0x3c);
  1922. i2c_r1(gspca_dev, 0x12, &value);
  1923. i2c_w1(gspca_dev, 0x12, (value & 0x7) | 0x40);
  1924. }
  1925. break;
  1926. case SENSOR_MT9M111:
  1927. if (mode & MODE_SXGA) {
  1928. i2c_w2(gspca_dev, 0xf0, 0x0002);
  1929. i2c_w2(gspca_dev, 0xc8, 0x970b);
  1930. i2c_w2(gspca_dev, 0xf0, 0x0000);
  1931. } else {
  1932. i2c_w2(gspca_dev, 0xf0, 0x0002);
  1933. i2c_w2(gspca_dev, 0xc8, 0x8000);
  1934. i2c_w2(gspca_dev, 0xf0, 0x0000);
  1935. }
  1936. break;
  1937. }
  1938. }
  1939. #define HW_WIN(mode, hstart, vstart) \
  1940. ((const u8 []){hstart, 0, vstart, 0, \
  1941. (mode & MODE_SXGA ? 1280 >> 4 : 640 >> 4), \
  1942. (mode & MODE_SXGA ? 1024 >> 3 : 480 >> 3)})
  1943. #define CLR_WIN(width, height) \
  1944. ((const u8 [])\
  1945. {0, width >> 2, 0, height >> 1,\
  1946. ((width >> 10) & 0x01) | ((height >> 8) & 0x6)})
  1947. static int sd_start(struct gspca_dev *gspca_dev)
  1948. {
  1949. struct sd *sd = (struct sd *) gspca_dev;
  1950. int mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  1951. int width = gspca_dev->width;
  1952. int height = gspca_dev->height;
  1953. u8 fmt, scale = 0;
  1954. sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
  1955. if (sd->jpeg_hdr == NULL)
  1956. return -ENOMEM;
  1957. jpeg_define(sd->jpeg_hdr, height, width,
  1958. 0x21);
  1959. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1960. if (mode & MODE_RAW)
  1961. fmt = 0x2d;
  1962. else if (mode & MODE_JPEG)
  1963. fmt = 0x2c;
  1964. else
  1965. fmt = 0x2f;
  1966. switch (mode & 0x0f) {
  1967. case 3:
  1968. scale = 0xc0;
  1969. info("Set 1280x1024");
  1970. break;
  1971. case 2:
  1972. scale = 0x80;
  1973. info("Set 640x480");
  1974. break;
  1975. case 1:
  1976. scale = 0x90;
  1977. info("Set 320x240");
  1978. break;
  1979. case 0:
  1980. scale = 0xa0;
  1981. info("Set 160x120");
  1982. break;
  1983. }
  1984. configure_sensor_output(gspca_dev, mode);
  1985. reg_w(gspca_dev, 0x1100, sd->jpeg_hdr + JPEG_QT0_OFFSET, 64);
  1986. reg_w(gspca_dev, 0x1140, sd->jpeg_hdr + JPEG_QT1_OFFSET, 64);
  1987. reg_w(gspca_dev, 0x10fb, CLR_WIN(width, height), 5);
  1988. reg_w(gspca_dev, 0x1180, HW_WIN(mode, sd->hstart, sd->vstart), 6);
  1989. reg_w1(gspca_dev, 0x1189, scale);
  1990. reg_w1(gspca_dev, 0x10e0, fmt);
  1991. set_cmatrix(gspca_dev);
  1992. set_gamma(gspca_dev);
  1993. set_redblue(gspca_dev);
  1994. set_gain(gspca_dev);
  1995. set_exposure(gspca_dev);
  1996. set_hvflip(gspca_dev);
  1997. reg_r(gspca_dev, 0x1061, 1);
  1998. reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] | 0x02);
  1999. return 0;
  2000. }
  2001. static void sd_stopN(struct gspca_dev *gspca_dev)
  2002. {
  2003. reg_r(gspca_dev, 0x1061, 1);
  2004. reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] & ~0x02);
  2005. }
  2006. static void sd_stop0(struct gspca_dev *gspca_dev)
  2007. {
  2008. struct sd *sd = (struct sd *) gspca_dev;
  2009. kfree(sd->jpeg_hdr);
  2010. }
  2011. static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
  2012. {
  2013. struct sd *sd = (struct sd *) gspca_dev;
  2014. s16 new_exp;
  2015. /*
  2016. * some hardcoded values are present
  2017. * like those for maximal/minimal exposure
  2018. * and exposure steps
  2019. */
  2020. if (avg_lum < MIN_AVG_LUM) {
  2021. if (sd->exposure > 0x1770)
  2022. return;
  2023. new_exp = sd->exposure + sd->exposure_step;
  2024. if (new_exp > 0x1770)
  2025. new_exp = 0x1770;
  2026. if (new_exp < 0x10)
  2027. new_exp = 0x10;
  2028. sd->exposure = new_exp;
  2029. set_exposure(gspca_dev);
  2030. sd->older_step = sd->old_step;
  2031. sd->old_step = 1;
  2032. if (sd->old_step ^ sd->older_step)
  2033. sd->exposure_step /= 2;
  2034. else
  2035. sd->exposure_step += 2;
  2036. }
  2037. if (avg_lum > MAX_AVG_LUM) {
  2038. if (sd->exposure < 0x10)
  2039. return;
  2040. new_exp = sd->exposure - sd->exposure_step;
  2041. if (new_exp > 0x1700)
  2042. new_exp = 0x1770;
  2043. if (new_exp < 0x10)
  2044. new_exp = 0x10;
  2045. sd->exposure = new_exp;
  2046. set_exposure(gspca_dev);
  2047. sd->older_step = sd->old_step;
  2048. sd->old_step = 0;
  2049. if (sd->old_step ^ sd->older_step)
  2050. sd->exposure_step /= 2;
  2051. else
  2052. sd->exposure_step += 2;
  2053. }
  2054. }
  2055. static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum)
  2056. {
  2057. struct sd *sd = (struct sd *) gspca_dev;
  2058. if (avg_lum < MIN_AVG_LUM) {
  2059. if (sd->gain + 1 <= 28) {
  2060. sd->gain++;
  2061. set_gain(gspca_dev);
  2062. }
  2063. }
  2064. if (avg_lum > MAX_AVG_LUM) {
  2065. if (sd->gain > 0) {
  2066. sd->gain--;
  2067. set_gain(gspca_dev);
  2068. }
  2069. }
  2070. }
  2071. static void sd_dqcallback(struct gspca_dev *gspca_dev)
  2072. {
  2073. struct sd *sd = (struct sd *) gspca_dev;
  2074. int avg_lum;
  2075. if (!sd->auto_exposure)
  2076. return;
  2077. avg_lum = atomic_read(&sd->avg_lum);
  2078. if (sd->sensor == SENSOR_SOI968)
  2079. do_autogain(gspca_dev, avg_lum);
  2080. else
  2081. do_autoexposure(gspca_dev, avg_lum);
  2082. }
  2083. #ifdef CONFIG_INPUT
  2084. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2085. u8 *data, /* interrupt packet */
  2086. int len) /* interrupt packet length */
  2087. {
  2088. struct sd *sd = (struct sd *) gspca_dev;
  2089. int ret = -EINVAL;
  2090. if (sd->flags & HAS_BUTTON && len == 1) {
  2091. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2092. input_sync(gspca_dev->input_dev);
  2093. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2094. input_sync(gspca_dev->input_dev);
  2095. ret = 0;
  2096. }
  2097. return ret;
  2098. }
  2099. #endif
  2100. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2101. u8 *data, /* isoc packet */
  2102. int len) /* iso packet length */
  2103. {
  2104. struct sd *sd = (struct sd *) gspca_dev;
  2105. int avg_lum;
  2106. static u8 frame_header[] =
  2107. {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96};
  2108. if (len == 64 && memcmp(data, frame_header, 6) == 0) {
  2109. avg_lum = ((data[35] >> 2) & 3) |
  2110. (data[20] << 2) |
  2111. (data[19] << 10);
  2112. avg_lum += ((data[35] >> 4) & 3) |
  2113. (data[22] << 2) |
  2114. (data[21] << 10);
  2115. avg_lum += ((data[35] >> 6) & 3) |
  2116. (data[24] << 2) |
  2117. (data[23] << 10);
  2118. avg_lum += (data[36] & 3) |
  2119. (data[26] << 2) |
  2120. (data[25] << 10);
  2121. avg_lum += ((data[36] >> 2) & 3) |
  2122. (data[28] << 2) |
  2123. (data[27] << 10);
  2124. avg_lum += ((data[36] >> 4) & 3) |
  2125. (data[30] << 2) |
  2126. (data[29] << 10);
  2127. avg_lum += ((data[36] >> 6) & 3) |
  2128. (data[32] << 2) |
  2129. (data[31] << 10);
  2130. avg_lum += ((data[44] >> 4) & 3) |
  2131. (data[34] << 2) |
  2132. (data[33] << 10);
  2133. avg_lum >>= 9;
  2134. atomic_set(&sd->avg_lum, avg_lum);
  2135. gspca_frame_add(gspca_dev, LAST_PACKET,
  2136. data, len);
  2137. return;
  2138. }
  2139. if (gspca_dev->last_packet_type == LAST_PACKET) {
  2140. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv
  2141. & MODE_JPEG) {
  2142. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2143. sd->jpeg_hdr, JPEG_HDR_SZ);
  2144. gspca_frame_add(gspca_dev, INTER_PACKET,
  2145. data, len);
  2146. } else {
  2147. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2148. data, len);
  2149. }
  2150. } else {
  2151. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2152. }
  2153. }
  2154. /* sub-driver description */
  2155. static const struct sd_desc sd_desc = {
  2156. .name = MODULE_NAME,
  2157. .ctrls = sd_ctrls,
  2158. .nctrls = ARRAY_SIZE(sd_ctrls),
  2159. .config = sd_config,
  2160. .init = sd_init,
  2161. .start = sd_start,
  2162. .stopN = sd_stopN,
  2163. .stop0 = sd_stop0,
  2164. .pkt_scan = sd_pkt_scan,
  2165. #ifdef CONFIG_INPUT
  2166. .int_pkt_scan = sd_int_pkt_scan,
  2167. #endif
  2168. .dq_callback = sd_dqcallback,
  2169. #ifdef CONFIG_VIDEO_ADV_DEBUG
  2170. .set_register = sd_dbg_s_register,
  2171. .get_register = sd_dbg_g_register,
  2172. #endif
  2173. .get_chip_ident = sd_chip_ident,
  2174. };
  2175. #define SN9C20X(sensor, i2c_addr, flags) \
  2176. .driver_info = (flags << 16) \
  2177. | (SENSOR_ ## sensor << 8) \
  2178. | (i2c_addr)
  2179. static const __devinitdata struct usb_device_id device_table[] = {
  2180. {USB_DEVICE(0x0c45, 0x6240), SN9C20X(MT9M001, 0x5d, 0)},
  2181. {USB_DEVICE(0x0c45, 0x6242), SN9C20X(MT9M111, 0x5d, 0)},
  2182. {USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)},
  2183. {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, HAS_BUTTON)},
  2184. {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30, 0)},
  2185. {USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)},
  2186. {USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)},
  2187. {USB_DEVICE(0x0c45, 0x6260), SN9C20X(OV7670, 0x21, 0)},
  2188. {USB_DEVICE(0x0c45, 0x6270), SN9C20X(MT9VPRB, 0x00, 0)},
  2189. {USB_DEVICE(0x0c45, 0x627b), SN9C20X(OV7660, 0x21, 0)},
  2190. {USB_DEVICE(0x0c45, 0x627c), SN9C20X(HV7131R, 0x11, 0)},
  2191. {USB_DEVICE(0x0c45, 0x627f), SN9C20X(OV9650, 0x30, 0)},
  2192. {USB_DEVICE(0x0c45, 0x6280), SN9C20X(MT9M001, 0x5d, 0)},
  2193. {USB_DEVICE(0x0c45, 0x6282), SN9C20X(MT9M111, 0x5d, 0)},
  2194. {USB_DEVICE(0x0c45, 0x6288), SN9C20X(OV9655, 0x30, HAS_BUTTON)},
  2195. {USB_DEVICE(0x0c45, 0x628e), SN9C20X(SOI968, 0x30, 0)},
  2196. {USB_DEVICE(0x0c45, 0x628f), SN9C20X(OV9650, 0x30, 0)},
  2197. {USB_DEVICE(0x0c45, 0x62a0), SN9C20X(OV7670, 0x21, 0)},
  2198. {USB_DEVICE(0x0c45, 0x62b0), SN9C20X(MT9VPRB, 0x00, 0)},
  2199. {USB_DEVICE(0x0c45, 0x62b3), SN9C20X(OV9655, 0x30, 0)},
  2200. {USB_DEVICE(0x0c45, 0x62bb), SN9C20X(OV7660, 0x21, HAS_BUTTON)},
  2201. {USB_DEVICE(0x0c45, 0x62bc), SN9C20X(HV7131R, 0x11, 0)},
  2202. {USB_DEVICE(0x045e, 0x00f4), SN9C20X(OV9650, 0x30, 0)},
  2203. {USB_DEVICE(0x145f, 0x013d), SN9C20X(OV7660, 0x21, 0)},
  2204. {USB_DEVICE(0x0458, 0x7029), SN9C20X(HV7131R, 0x11, 0)},
  2205. {USB_DEVICE(0xa168, 0x0610), SN9C20X(HV7131R, 0x11, 0)},
  2206. {USB_DEVICE(0xa168, 0x0611), SN9C20X(HV7131R, 0x11, 0)},
  2207. {USB_DEVICE(0xa168, 0x0613), SN9C20X(HV7131R, 0x11, 0)},
  2208. {USB_DEVICE(0xa168, 0x0618), SN9C20X(HV7131R, 0x11, 0)},
  2209. {USB_DEVICE(0xa168, 0x0614), SN9C20X(MT9M111, 0x5d, HAS_BUTTON)},
  2210. {USB_DEVICE(0xa168, 0x0615), SN9C20X(MT9M111, 0x5d, 0)},
  2211. {USB_DEVICE(0xa168, 0x0617), SN9C20X(MT9M111, 0x5d, 0)},
  2212. {}
  2213. };
  2214. MODULE_DEVICE_TABLE(usb, device_table);
  2215. /* -- device connect -- */
  2216. static int sd_probe(struct usb_interface *intf,
  2217. const struct usb_device_id *id)
  2218. {
  2219. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2220. THIS_MODULE);
  2221. }
  2222. static struct usb_driver sd_driver = {
  2223. .name = MODULE_NAME,
  2224. .id_table = device_table,
  2225. .probe = sd_probe,
  2226. .disconnect = gspca_disconnect,
  2227. #ifdef CONFIG_PM
  2228. .suspend = gspca_suspend,
  2229. .resume = gspca_resume,
  2230. .reset_resume = gspca_resume,
  2231. #endif
  2232. };
  2233. /* -- module insert / remove -- */
  2234. static int __init sd_mod_init(void)
  2235. {
  2236. int ret;
  2237. ret = usb_register(&sd_driver);
  2238. if (ret < 0)
  2239. return ret;
  2240. info("registered");
  2241. return 0;
  2242. }
  2243. static void __exit sd_mod_exit(void)
  2244. {
  2245. usb_deregister(&sd_driver);
  2246. info("deregistered");
  2247. }
  2248. module_init(sd_mod_init);
  2249. module_exit(sd_mod_exit);