sn9c20x.c 69 KB

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