sn9c20x.c 69 KB

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