sn9c20x.c 71 KB

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