sn9c20x.c 69 KB

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