sn9c20x.c 69 KB

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