sonixj.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  3. *
  4. * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define MODULE_NAME "sonixj"
  22. #include "gspca.h"
  23. #include "jpeg.h"
  24. #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
  25. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  26. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  27. MODULE_LICENSE("GPL");
  28. /* specific webcam descriptor */
  29. struct sd {
  30. struct gspca_dev gspca_dev; /* !! must be the first item */
  31. atomic_t avg_lum;
  32. u32 exposure;
  33. u16 brightness;
  34. u8 contrast;
  35. u8 colors;
  36. u8 autogain;
  37. u8 blue;
  38. u8 red;
  39. u8 gamma;
  40. u8 vflip; /* ov7630/ov7648 only */
  41. u8 sharpness;
  42. u8 infrared; /* mt9v111 only */
  43. u8 freq; /* ov76xx only */
  44. u8 quality; /* image quality */
  45. #define QUALITY_MIN 60
  46. #define QUALITY_MAX 95
  47. #define QUALITY_DEF 80
  48. u8 jpegqual; /* webcam quality */
  49. u8 reg18;
  50. s8 ag_cnt;
  51. #define AG_CNT_START 13
  52. u8 bridge;
  53. #define BRIDGE_SN9C102P 0
  54. #define BRIDGE_SN9C105 1
  55. #define BRIDGE_SN9C110 2
  56. #define BRIDGE_SN9C120 3
  57. u8 sensor; /* Type of image sensor chip */
  58. #define SENSOR_ADCM1700 0
  59. #define SENSOR_HV7131R 1
  60. #define SENSOR_MI0360 2
  61. #define SENSOR_MO4000 3
  62. #define SENSOR_MT9V111 4
  63. #define SENSOR_OM6802 5
  64. #define SENSOR_OV7630 6
  65. #define SENSOR_OV7648 7
  66. #define SENSOR_OV7660 8
  67. #define SENSOR_PO1030 9
  68. #define SENSOR_SP80708 10
  69. u8 i2c_addr;
  70. u8 *jpeg_hdr;
  71. };
  72. /* V4L2 controls supported by the driver */
  73. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  74. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  75. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  76. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  77. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  78. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  79. static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
  80. static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
  81. static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
  82. static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
  83. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
  84. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
  85. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  86. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  87. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  88. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  89. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  90. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  91. static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
  92. static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
  93. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  94. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  95. static const struct ctrl sd_ctrls[] = {
  96. #define BRIGHTNESS_IDX 0
  97. {
  98. {
  99. .id = V4L2_CID_BRIGHTNESS,
  100. .type = V4L2_CTRL_TYPE_INTEGER,
  101. .name = "Brightness",
  102. .minimum = 0,
  103. #define BRIGHTNESS_MAX 0xffff
  104. .maximum = BRIGHTNESS_MAX,
  105. .step = 1,
  106. #define BRIGHTNESS_DEF 0x8000
  107. .default_value = BRIGHTNESS_DEF,
  108. },
  109. .set = sd_setbrightness,
  110. .get = sd_getbrightness,
  111. },
  112. #define CONTRAST_IDX 1
  113. {
  114. {
  115. .id = V4L2_CID_CONTRAST,
  116. .type = V4L2_CTRL_TYPE_INTEGER,
  117. .name = "Contrast",
  118. .minimum = 0,
  119. #define CONTRAST_MAX 127
  120. .maximum = CONTRAST_MAX,
  121. .step = 1,
  122. #define CONTRAST_DEF 63
  123. .default_value = CONTRAST_DEF,
  124. },
  125. .set = sd_setcontrast,
  126. .get = sd_getcontrast,
  127. },
  128. #define COLOR_IDX 2
  129. {
  130. {
  131. .id = V4L2_CID_SATURATION,
  132. .type = V4L2_CTRL_TYPE_INTEGER,
  133. .name = "Saturation",
  134. .minimum = 0,
  135. .maximum = 40,
  136. .step = 1,
  137. #define COLOR_DEF 25
  138. .default_value = COLOR_DEF,
  139. },
  140. .set = sd_setcolors,
  141. .get = sd_getcolors,
  142. },
  143. #define BLUE_BALANCE_IDX 3
  144. {
  145. {
  146. .id = V4L2_CID_BLUE_BALANCE,
  147. .type = V4L2_CTRL_TYPE_INTEGER,
  148. .name = "Blue Balance",
  149. .minimum = 24,
  150. .maximum = 40,
  151. .step = 1,
  152. #define BLUE_BALANCE_DEF 32
  153. .default_value = BLUE_BALANCE_DEF,
  154. },
  155. .set = sd_setblue_balance,
  156. .get = sd_getblue_balance,
  157. },
  158. #define RED_BALANCE_IDX 4
  159. {
  160. {
  161. .id = V4L2_CID_RED_BALANCE,
  162. .type = V4L2_CTRL_TYPE_INTEGER,
  163. .name = "Red Balance",
  164. .minimum = 24,
  165. .maximum = 40,
  166. .step = 1,
  167. #define RED_BALANCE_DEF 32
  168. .default_value = RED_BALANCE_DEF,
  169. },
  170. .set = sd_setred_balance,
  171. .get = sd_getred_balance,
  172. },
  173. #define GAMMA_IDX 5
  174. {
  175. {
  176. .id = V4L2_CID_GAMMA,
  177. .type = V4L2_CTRL_TYPE_INTEGER,
  178. .name = "Gamma",
  179. .minimum = 0,
  180. .maximum = 40,
  181. .step = 1,
  182. #define GAMMA_DEF 20
  183. .default_value = GAMMA_DEF,
  184. },
  185. .set = sd_setgamma,
  186. .get = sd_getgamma,
  187. },
  188. #define AUTOGAIN_IDX 6
  189. {
  190. {
  191. .id = V4L2_CID_AUTOGAIN,
  192. .type = V4L2_CTRL_TYPE_BOOLEAN,
  193. .name = "Auto Gain",
  194. .minimum = 0,
  195. .maximum = 1,
  196. .step = 1,
  197. #define AUTOGAIN_DEF 1
  198. .default_value = AUTOGAIN_DEF,
  199. },
  200. .set = sd_setautogain,
  201. .get = sd_getautogain,
  202. },
  203. /* ov7630/ov7648 only */
  204. #define VFLIP_IDX 7
  205. {
  206. {
  207. .id = V4L2_CID_VFLIP,
  208. .type = V4L2_CTRL_TYPE_BOOLEAN,
  209. .name = "Vflip",
  210. .minimum = 0,
  211. .maximum = 1,
  212. .step = 1,
  213. #define VFLIP_DEF 0
  214. .default_value = VFLIP_DEF,
  215. },
  216. .set = sd_setvflip,
  217. .get = sd_getvflip,
  218. },
  219. #define SHARPNESS_IDX 8
  220. {
  221. {
  222. .id = V4L2_CID_SHARPNESS,
  223. .type = V4L2_CTRL_TYPE_INTEGER,
  224. .name = "Sharpness",
  225. .minimum = 0,
  226. .maximum = 255,
  227. .step = 1,
  228. #define SHARPNESS_DEF 90
  229. .default_value = SHARPNESS_DEF,
  230. },
  231. .set = sd_setsharpness,
  232. .get = sd_getsharpness,
  233. },
  234. /* mt9v111 only */
  235. #define INFRARED_IDX 9
  236. {
  237. {
  238. .id = V4L2_CID_INFRARED,
  239. .type = V4L2_CTRL_TYPE_BOOLEAN,
  240. .name = "Infrared",
  241. .minimum = 0,
  242. .maximum = 1,
  243. .step = 1,
  244. #define INFRARED_DEF 0
  245. .default_value = INFRARED_DEF,
  246. },
  247. .set = sd_setinfrared,
  248. .get = sd_getinfrared,
  249. },
  250. /* ov7630/ov7648/ov7660 only */
  251. #define FREQ_IDX 10
  252. {
  253. {
  254. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  255. .type = V4L2_CTRL_TYPE_MENU,
  256. .name = "Light frequency filter",
  257. .minimum = 0,
  258. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  259. .step = 1,
  260. #define FREQ_DEF 1
  261. .default_value = FREQ_DEF,
  262. },
  263. .set = sd_setfreq,
  264. .get = sd_getfreq,
  265. },
  266. };
  267. /* table of the disabled controls */
  268. static __u32 ctrl_dis[] = {
  269. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX) |
  270. (1 << AUTOGAIN_IDX), /* SENSOR_ADCM1700 0 */
  271. (1 << INFRARED_IDX) | (1 << FREQ_IDX),
  272. /* SENSOR_HV7131R 1 */
  273. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  274. /* SENSOR_MI0360 2 */
  275. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  276. /* SENSOR_MO4000 3 */
  277. (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  278. /* SENSOR_MT9V111 4 */
  279. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  280. /* SENSOR_OM6802 5 */
  281. (1 << INFRARED_IDX),
  282. /* SENSOR_OV7630 6 */
  283. (1 << INFRARED_IDX),
  284. /* SENSOR_OV7648 7 */
  285. (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
  286. /* SENSOR_OV7660 8 */
  287. (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
  288. (1 << FREQ_IDX), /* SENSOR_PO1030 9 */
  289. (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
  290. (1 << FREQ_IDX), /* SENSOR_SP80708 10 */
  291. };
  292. static const struct v4l2_pix_format cif_mode[] = {
  293. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  294. .bytesperline = 352,
  295. .sizeimage = 352 * 288 * 4 / 8 + 590,
  296. .colorspace = V4L2_COLORSPACE_JPEG,
  297. .priv = 0},
  298. };
  299. static const struct v4l2_pix_format vga_mode[] = {
  300. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  301. .bytesperline = 160,
  302. .sizeimage = 160 * 120 * 4 / 8 + 590,
  303. .colorspace = V4L2_COLORSPACE_JPEG,
  304. .priv = 2},
  305. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  306. .bytesperline = 320,
  307. .sizeimage = 320 * 240 * 3 / 8 + 590,
  308. .colorspace = V4L2_COLORSPACE_JPEG,
  309. .priv = 1},
  310. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  311. .bytesperline = 640,
  312. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  313. .sizeimage = 640 * 480 * 3 / 4 + 590,
  314. .colorspace = V4L2_COLORSPACE_JPEG,
  315. .priv = 0},
  316. };
  317. static const u8 sn_adcm1700[0x1c] = {
  318. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  319. 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
  320. /* reg8 reg9 rega regb regc regd rege regf */
  321. 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  322. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  323. 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
  324. /* reg18 reg19 reg1a reg1b */
  325. 0x06, 0x00, 0x00, 0x00
  326. };
  327. /*Data from sn9c102p+hv7131r */
  328. static const u8 sn_hv7131[0x1c] = {
  329. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  330. 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
  331. /* reg8 reg9 rega regb regc regd rege regf */
  332. 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  333. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  334. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  335. /* reg18 reg19 reg1a reg1b */
  336. 0x0a, 0x00, 0x00, 0x00
  337. };
  338. static const u8 sn_mi0360[0x1c] = {
  339. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  340. 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
  341. /* reg8 reg9 rega regb regc regd rege regf */
  342. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  343. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  344. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  345. /* reg18 reg19 reg1a reg1b */
  346. 0x06, 0x00, 0x00, 0x00
  347. };
  348. static const u8 sn_mo4000[0x1c] = {
  349. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  350. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  351. /* reg8 reg9 rega regb regc regd rege regf */
  352. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  353. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  354. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  355. /* reg18 reg19 reg1a reg1b */
  356. 0x08, 0x00, 0x00, 0x00
  357. };
  358. static const u8 sn_mt9v111[0x1c] = {
  359. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  360. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  361. /* reg8 reg9 rega regb regc regd rege regf */
  362. 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  363. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  364. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  365. /* reg18 reg19 reg1a reg1b */
  366. 0x06, 0x00, 0x00, 0x00
  367. };
  368. static const u8 sn_om6802[0x1c] = {
  369. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  370. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
  371. /* reg8 reg9 rega regb regc regd rege regf */
  372. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  373. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  374. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  375. /* reg18 reg19 reg1a reg1b */
  376. 0x05, 0x00, 0x00, 0x00
  377. };
  378. static const u8 sn_ov7630[0x1c] = {
  379. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  380. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
  381. /* reg8 reg9 rega regb regc regd rege regf */
  382. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  383. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  384. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  385. /* reg18 reg19 reg1a reg1b */
  386. 0x0b, 0x00, 0x00, 0x00
  387. };
  388. static const u8 sn_ov7648[0x1c] = {
  389. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  390. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  391. /* reg8 reg9 rega regb regc regd rege regf */
  392. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  393. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  394. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  395. /* reg18 reg19 reg1a reg1b */
  396. 0x0b, 0x00, 0x00, 0x00
  397. };
  398. static const u8 sn_ov7660[0x1c] = {
  399. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  400. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  401. /* reg8 reg9 rega regb regc regd rege regf */
  402. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  403. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  404. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  405. /* reg18 reg19 reg1a reg1b */
  406. 0x07, 0x00, 0x00, 0x00
  407. };
  408. static const u8 sn_po1030[0x1c] = {
  409. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  410. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  411. /* reg8 reg9 rega regb regc regd rege regf */
  412. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  413. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  414. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
  415. /* reg18 reg19 reg1a reg1b */
  416. 0x07, 0x00, 0x00, 0x00
  417. };
  418. static const u8 sn_sp80708[0x1c] = {
  419. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  420. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  421. /* reg8 reg9 rega regb regc regd rege regf */
  422. 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  423. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  424. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  425. /* reg18 reg19 reg1a reg1b */
  426. 0x07, 0x00, 0x00, 0x00
  427. };
  428. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  429. static const u8 *sn_tb[] = {
  430. sn_adcm1700,
  431. sn_hv7131,
  432. sn_mi0360,
  433. sn_mo4000,
  434. sn_mt9v111,
  435. sn_om6802,
  436. sn_ov7630,
  437. sn_ov7648,
  438. sn_ov7660,
  439. sn_po1030,
  440. sn_sp80708
  441. };
  442. /* default gamma table */
  443. static const u8 gamma_def[17] = {
  444. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  445. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  446. };
  447. /* gamma for sensor ADCM1700 */
  448. static const u8 gamma_spec_0[17] = {
  449. 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
  450. 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
  451. };
  452. /* gamma for sensors HV7131R and MT9V111 */
  453. static const u8 gamma_spec_1[17] = {
  454. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  455. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  456. };
  457. /* gamma for sensor SP80708 */
  458. static const u8 gamma_spec_2[17] = {
  459. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  460. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  461. };
  462. /* color matrix and offsets */
  463. static const u8 reg84[] = {
  464. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  465. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  466. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  467. 0x00, 0x00, 0x00 /* YUV offsets */
  468. };
  469. static const u8 adcm1700_sensor_init[][8] = {
  470. {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
  471. {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
  472. {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  473. {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  474. {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  475. {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
  476. {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
  477. {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
  478. {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
  479. {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
  480. {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  481. {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
  482. {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  483. {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
  484. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  485. {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
  486. {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  487. {}
  488. };
  489. static const u8 adcm1700_sensor_param1[][8] = {
  490. {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
  491. {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
  492. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  493. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  494. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  495. {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
  496. {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
  497. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  498. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  499. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  500. {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
  501. {}
  502. };
  503. static const u8 hv7131r_sensor_init[][8] = {
  504. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  505. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  506. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  507. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  508. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  509. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  510. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  511. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  512. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  513. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  514. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  515. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  516. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  517. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  518. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  519. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  520. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  521. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  522. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  523. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  524. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  525. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  526. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  527. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  528. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  529. {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
  530. /* set sensor clock */
  531. {}
  532. };
  533. static const u8 mi0360_sensor_init[][8] = {
  534. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  535. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  536. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  537. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  538. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  539. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  540. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  541. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  542. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  543. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  544. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  545. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  546. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  547. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  548. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  549. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  550. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  551. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  552. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  553. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  554. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  555. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  556. {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
  557. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  558. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  559. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  560. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  561. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  562. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  563. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  564. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  565. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  566. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  567. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  568. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  569. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  570. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  571. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  572. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  573. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  574. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  575. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  576. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  577. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  578. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  579. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  580. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  581. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  582. {}
  583. };
  584. static const u8 mo4000_sensor_init[][8] = {
  585. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  586. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  587. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  588. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  589. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  590. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  591. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  592. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  593. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  594. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  595. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  596. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  597. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  598. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  599. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  600. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  601. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  602. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  603. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  604. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  605. {}
  606. };
  607. static const u8 mt9v111_sensor_init[][8] = {
  608. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  609. {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  610. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  611. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  612. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  613. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  614. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  615. {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
  616. {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
  617. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  618. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  619. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  620. {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
  621. {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
  622. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  623. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  624. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  625. {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
  626. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  627. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  628. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  629. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  630. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  631. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  632. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  633. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  634. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  635. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  636. {}
  637. };
  638. static const u8 mt9v111_sensor_param1[][8] = {
  639. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  640. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  641. {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
  642. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
  643. {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
  644. /*******/
  645. {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
  646. {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
  647. {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
  648. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  649. {}
  650. };
  651. static const u8 om6802_init0[2][8] = {
  652. /*fixme: variable*/
  653. {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
  654. {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
  655. };
  656. static const u8 om6802_sensor_init[][8] = {
  657. {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
  658. /* factory mode */
  659. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  660. /* output raw RGB */
  661. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  662. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  663. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  664. /* auto-exposure speed (0) / white balance mode (auto RGB) */
  665. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  666. * set color mode */
  667. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  668. * max AGC value in AE */
  669. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  670. * preset AGC */
  671. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  672. * preset brightness */
  673. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  674. * preset contrast */
  675. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  676. * preset gamma */
  677. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  678. /* luminance mode (0x4f -> AutoExpo on) */
  679. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  680. /* preset shutter */
  681. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  682. * auto frame rate */
  683. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  684. {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  685. {}
  686. };
  687. static const u8 om6802_sensor_param1[][8] = {
  688. {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
  689. {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
  690. {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
  691. {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
  692. {}
  693. };
  694. static const u8 ov7630_sensor_init[][8] = {
  695. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  696. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  697. {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  698. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  699. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  700. {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  701. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  702. /* win: i2c_r from 00 to 80 */
  703. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  704. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  705. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  706. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  707. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  708. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  709. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  710. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  711. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  712. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  713. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  714. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  715. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  716. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  717. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  718. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  719. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  720. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  721. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  722. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  723. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  724. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  725. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  726. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  727. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  728. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  729. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  730. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  731. /* */
  732. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  733. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  734. /*fixme: + 0x12, 0x04*/
  735. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  736. * set by setvflip */
  737. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  738. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  739. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  740. /* */
  741. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  742. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  743. /* */
  744. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  745. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  746. {}
  747. };
  748. static const u8 ov7648_sensor_init[][8] = {
  749. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  750. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  751. {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  752. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  753. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  754. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  755. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  756. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  757. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  758. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  759. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  760. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  761. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  762. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  763. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  764. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  765. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  766. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  767. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  768. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  769. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  770. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  771. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  772. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  773. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  774. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  775. {}
  776. };
  777. static const u8 ov7648_sensor_param1[][8] = {
  778. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  779. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  780. * set by setvflip */
  781. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  782. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  783. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  784. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  785. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  786. /*...*/
  787. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  788. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  789. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  790. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  791. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  792. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  793. {}
  794. };
  795. static const u8 ov7660_sensor_init[][8] = {
  796. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  797. {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  798. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  799. /* Outformat = rawRGB */
  800. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  801. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  802. /* GAIN BLUE RED VREF */
  803. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  804. /* COM 1 BAVE GEAVE AECHH */
  805. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  806. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  807. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  808. /* AECH CLKRC COM7 COM8 */
  809. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  810. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  811. /* HSTART HSTOP VSTRT VSTOP */
  812. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  813. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  814. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  815. /* BOS GBOS GROS ROS (BGGR offset) */
  816. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  817. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  818. /* AEW AEB VPT BBIAS */
  819. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  820. /* GbBIAS RSVD EXHCH EXHCL */
  821. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  822. /* RBIAS ADVFL ASDVFH YAVE */
  823. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  824. /* HSYST HSYEN HREF */
  825. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  826. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  827. /* ADC ACOM OFON TSLB */
  828. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  829. /* COM11 COM12 COM13 COM14 */
  830. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  831. /* EDGE COM15 COM16 COM17 */
  832. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  833. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  834. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  835. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  836. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  837. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  838. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  839. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  840. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  841. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  842. /* LCC1 LCC2 LCC3 LCC4 */
  843. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  844. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  845. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  846. /* band gap reference [0:3] DBLV */
  847. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  848. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  849. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  850. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  851. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  852. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  853. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  854. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  855. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  856. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  857. /* not in all ms-win traces*/
  858. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  859. {}
  860. };
  861. static const u8 ov7660_sensor_param1[][8] = {
  862. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  863. /* bits[3..0]reserved */
  864. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  865. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  866. /* VREF vertical frame ctrl */
  867. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  868. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  869. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  870. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  871. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  872. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  873. /****** (some exchanges in the win trace) ******/
  874. /*fixme:param2*/
  875. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  876. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  877. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  878. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  879. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  880. /****** (some exchanges in the win trace) ******/
  881. /******!! startsensor KO if changed !!****/
  882. /*fixme: param3*/
  883. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  884. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  885. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  886. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  887. {}
  888. };
  889. static const u8 po1030_sensor_init[][8] = {
  890. /* the sensor registers are described in m5602/m5602_po1030.h */
  891. {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
  892. {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  893. {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
  894. {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
  895. {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
  896. {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  897. {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
  898. {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  899. {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
  900. {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
  901. {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
  902. {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
  903. {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  904. {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  905. {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
  906. {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
  907. {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
  908. {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
  909. {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
  910. {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
  911. {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  912. {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  913. {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
  914. {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
  915. {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
  916. {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
  917. {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
  918. {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
  919. {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  920. {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  921. {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
  922. {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
  923. {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
  924. {}
  925. };
  926. static const u8 po1030_sensor_param1[][8] = {
  927. /* from ms-win traces - these values change with auto gain/expo/wb.. */
  928. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  929. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  930. /* mean values */
  931. {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
  932. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
  933. {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
  934. {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
  935. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
  936. {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
  937. /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
  938. {}
  939. };
  940. static const u8 sp80708_sensor_init[][8] = {
  941. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  942. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  943. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  944. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  945. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  946. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  947. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  948. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  949. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  950. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  951. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  952. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  953. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  954. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  955. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  956. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  957. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  958. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  959. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  960. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  961. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  962. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  963. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  964. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  965. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  966. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  967. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  968. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  969. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  970. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  971. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  972. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  973. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  974. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  975. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  976. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  977. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  978. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  979. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  980. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  981. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  982. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  983. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  984. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  985. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  986. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  987. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  988. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  989. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  990. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  991. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  992. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  993. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  994. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  995. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  996. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  997. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  998. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  999. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  1000. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  1001. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  1002. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1003. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  1004. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  1005. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  1006. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  1007. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  1008. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  1009. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  1010. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  1011. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  1012. {}
  1013. };
  1014. static const u8 sp80708_sensor_param1[][8] = {
  1015. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1016. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1017. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  1018. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  1019. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  1020. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  1021. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  1022. {}
  1023. };
  1024. static const u8 (*sensor_init[11])[8] = {
  1025. adcm1700_sensor_init, /* ADCM1700 0 */
  1026. hv7131r_sensor_init, /* HV7131R 1 */
  1027. mi0360_sensor_init, /* MI0360 2 */
  1028. mo4000_sensor_init, /* MO4000 3 */
  1029. mt9v111_sensor_init, /* MT9V111 4 */
  1030. om6802_sensor_init, /* OM6802 5 */
  1031. ov7630_sensor_init, /* OV7630 6 */
  1032. ov7648_sensor_init, /* OV7648 7 */
  1033. ov7660_sensor_init, /* OV7660 8 */
  1034. po1030_sensor_init, /* PO1030 9 */
  1035. sp80708_sensor_init, /* SP80708 10 */
  1036. };
  1037. /* read <len> bytes to gspca_dev->usb_buf */
  1038. static void reg_r(struct gspca_dev *gspca_dev,
  1039. u16 value, int len)
  1040. {
  1041. #ifdef GSPCA_DEBUG
  1042. if (len > USB_BUF_SZ) {
  1043. err("reg_r: buffer overflow");
  1044. return;
  1045. }
  1046. #endif
  1047. usb_control_msg(gspca_dev->dev,
  1048. usb_rcvctrlpipe(gspca_dev->dev, 0),
  1049. 0,
  1050. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1051. value, 0,
  1052. gspca_dev->usb_buf, len,
  1053. 500);
  1054. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  1055. }
  1056. static void reg_w1(struct gspca_dev *gspca_dev,
  1057. u16 value,
  1058. u8 data)
  1059. {
  1060. PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
  1061. gspca_dev->usb_buf[0] = data;
  1062. usb_control_msg(gspca_dev->dev,
  1063. usb_sndctrlpipe(gspca_dev->dev, 0),
  1064. 0x08,
  1065. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1066. value,
  1067. 0,
  1068. gspca_dev->usb_buf, 1,
  1069. 500);
  1070. }
  1071. static void reg_w(struct gspca_dev *gspca_dev,
  1072. u16 value,
  1073. const u8 *buffer,
  1074. int len)
  1075. {
  1076. PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
  1077. value, buffer[0], buffer[1]);
  1078. #ifdef GSPCA_DEBUG
  1079. if (len > USB_BUF_SZ) {
  1080. err("reg_w: buffer overflow");
  1081. return;
  1082. }
  1083. #endif
  1084. memcpy(gspca_dev->usb_buf, buffer, len);
  1085. usb_control_msg(gspca_dev->dev,
  1086. usb_sndctrlpipe(gspca_dev->dev, 0),
  1087. 0x08,
  1088. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1089. value, 0,
  1090. gspca_dev->usb_buf, len,
  1091. 500);
  1092. }
  1093. /* I2C write 1 byte */
  1094. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1095. {
  1096. struct sd *sd = (struct sd *) gspca_dev;
  1097. PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
  1098. switch (sd->sensor) {
  1099. case SENSOR_ADCM1700:
  1100. case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */
  1101. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1102. break;
  1103. default: /* i2c command = a1 (400 kHz) */
  1104. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1105. break;
  1106. }
  1107. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1108. gspca_dev->usb_buf[2] = reg;
  1109. gspca_dev->usb_buf[3] = val;
  1110. gspca_dev->usb_buf[4] = 0;
  1111. gspca_dev->usb_buf[5] = 0;
  1112. gspca_dev->usb_buf[6] = 0;
  1113. gspca_dev->usb_buf[7] = 0x10;
  1114. usb_control_msg(gspca_dev->dev,
  1115. usb_sndctrlpipe(gspca_dev->dev, 0),
  1116. 0x08,
  1117. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1118. 0x08, /* value = i2c */
  1119. 0,
  1120. gspca_dev->usb_buf, 8,
  1121. 500);
  1122. }
  1123. /* I2C write 8 bytes */
  1124. static void i2c_w8(struct gspca_dev *gspca_dev,
  1125. const u8 *buffer)
  1126. {
  1127. memcpy(gspca_dev->usb_buf, buffer, 8);
  1128. usb_control_msg(gspca_dev->dev,
  1129. usb_sndctrlpipe(gspca_dev->dev, 0),
  1130. 0x08,
  1131. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1132. 0x08, 0, /* value, index */
  1133. gspca_dev->usb_buf, 8,
  1134. 500);
  1135. msleep(2);
  1136. }
  1137. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1138. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1139. {
  1140. struct sd *sd = (struct sd *) gspca_dev;
  1141. u8 mode[8];
  1142. switch (sd->sensor) {
  1143. case SENSOR_ADCM1700:
  1144. case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */
  1145. mode[0] = 0x80 | 0x10;
  1146. break;
  1147. default: /* i2c command = 91 (400 kHz) */
  1148. mode[0] = 0x81 | 0x10;
  1149. break;
  1150. }
  1151. mode[1] = sd->i2c_addr;
  1152. mode[2] = reg;
  1153. mode[3] = 0;
  1154. mode[4] = 0;
  1155. mode[5] = 0;
  1156. mode[6] = 0;
  1157. mode[7] = 0x10;
  1158. i2c_w8(gspca_dev, mode);
  1159. msleep(2);
  1160. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1161. mode[2] = 0;
  1162. i2c_w8(gspca_dev, mode);
  1163. msleep(2);
  1164. reg_r(gspca_dev, 0x0a, 5);
  1165. }
  1166. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1167. const u8 (*data)[8])
  1168. {
  1169. while ((*data)[0] != 0) {
  1170. if ((*data)[0] != 0xdd)
  1171. i2c_w8(gspca_dev, *data);
  1172. else
  1173. msleep((*data)[1]);
  1174. data++;
  1175. }
  1176. }
  1177. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1178. {
  1179. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1180. msleep(10);
  1181. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1182. msleep(10);
  1183. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1184. if (gspca_dev->usb_buf[0] == 0x02
  1185. && gspca_dev->usb_buf[1] == 0x09
  1186. && gspca_dev->usb_buf[2] == 0x01
  1187. && gspca_dev->usb_buf[3] == 0x00
  1188. && gspca_dev->usb_buf[4] == 0x00) {
  1189. PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
  1190. return;
  1191. }
  1192. PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
  1193. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1194. gspca_dev->usb_buf[2]);
  1195. }
  1196. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1197. {
  1198. struct sd *sd = (struct sd *) gspca_dev;
  1199. int i, j;
  1200. u16 val = 0;
  1201. static const u8 probe_tb[][4][8] = {
  1202. { /* mi0360 */
  1203. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1204. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1205. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1206. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1207. },
  1208. { /* mt9v111 */
  1209. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1210. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1211. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1212. {}
  1213. },
  1214. };
  1215. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1216. reg_w1(gspca_dev, 0x17, 0x62);
  1217. reg_w1(gspca_dev, 0x01, 0x08);
  1218. for (j = 0; j < 3; j++)
  1219. i2c_w8(gspca_dev, probe_tb[i][j]);
  1220. msleep(2);
  1221. reg_r(gspca_dev, 0x0a, 5);
  1222. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1223. if (probe_tb[i][3][0] != 0)
  1224. i2c_w8(gspca_dev, probe_tb[i][3]);
  1225. reg_w1(gspca_dev, 0x01, 0x29);
  1226. reg_w1(gspca_dev, 0x17, 0x42);
  1227. if (val != 0xffff)
  1228. break;
  1229. }
  1230. switch (val) {
  1231. case 0x823a:
  1232. PDEBUG(D_PROBE, "Sensor mt9v111");
  1233. sd->sensor = SENSOR_MT9V111;
  1234. break;
  1235. case 0x8243:
  1236. PDEBUG(D_PROBE, "Sensor mi0360");
  1237. break;
  1238. default:
  1239. PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
  1240. break;
  1241. }
  1242. }
  1243. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1244. {
  1245. struct sd *sd = (struct sd *) gspca_dev;
  1246. /* check ov76xx */
  1247. reg_w1(gspca_dev, 0x17, 0x62);
  1248. reg_w1(gspca_dev, 0x01, 0x08);
  1249. sd->i2c_addr = 0x21;
  1250. i2c_r(gspca_dev, 0x0a, 2);
  1251. if (gspca_dev->usb_buf[3] == 0x76) { /* ov76xx */
  1252. PDEBUG(D_PROBE, "Sensor ov%02x%02x",
  1253. gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
  1254. return;
  1255. }
  1256. /* reset */
  1257. reg_w1(gspca_dev, 0x01, 0x29);
  1258. reg_w1(gspca_dev, 0x17, 0x42);
  1259. /* check po1030 */
  1260. reg_w1(gspca_dev, 0x17, 0x62);
  1261. reg_w1(gspca_dev, 0x01, 0x08);
  1262. sd->i2c_addr = 0x6e;
  1263. i2c_r(gspca_dev, 0x00, 2);
  1264. if (gspca_dev->usb_buf[3] == 0x10 /* po1030 */
  1265. && gspca_dev->usb_buf[4] == 0x30) {
  1266. PDEBUG(D_PROBE, "Sensor po1030");
  1267. sd->sensor = SENSOR_PO1030;
  1268. return;
  1269. }
  1270. PDEBUG(D_PROBE, "Unknown sensor %02x%02x",
  1271. gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
  1272. }
  1273. static void bridge_init(struct gspca_dev *gspca_dev,
  1274. const u8 *sn9c1xx)
  1275. {
  1276. struct sd *sd = (struct sd *) gspca_dev;
  1277. const u8 *reg9a;
  1278. static const u8 reg9a_def[] =
  1279. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  1280. static const u8 reg9a_spec[] =
  1281. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  1282. static const u8 regd4[] = {0x60, 0x00, 0x00};
  1283. reg_w1(gspca_dev, 0xf1, 0x00);
  1284. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1285. /* configure gpio */
  1286. reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
  1287. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  1288. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  1289. switch (sd->sensor) {
  1290. case SENSOR_OV7660:
  1291. case SENSOR_PO1030:
  1292. case SENSOR_SP80708:
  1293. reg9a = reg9a_spec;
  1294. break;
  1295. default:
  1296. reg9a = reg9a_def;
  1297. break;
  1298. }
  1299. reg_w(gspca_dev, 0x9a, reg9a, 6);
  1300. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  1301. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  1302. switch (sd->sensor) {
  1303. case SENSOR_ADCM1700:
  1304. reg_w1(gspca_dev, 0x01, 0x43);
  1305. reg_w1(gspca_dev, 0x17, 0x62);
  1306. reg_w1(gspca_dev, 0x01, 0x42);
  1307. reg_w1(gspca_dev, 0x01, 0x42);
  1308. break;
  1309. case SENSOR_MT9V111:
  1310. reg_w1(gspca_dev, 0x01, 0x61);
  1311. reg_w1(gspca_dev, 0x17, 0x61);
  1312. reg_w1(gspca_dev, 0x01, 0x60);
  1313. reg_w1(gspca_dev, 0x01, 0x40);
  1314. break;
  1315. case SENSOR_OM6802:
  1316. msleep(10);
  1317. reg_w1(gspca_dev, 0x02, 0x73);
  1318. reg_w1(gspca_dev, 0x17, 0x60);
  1319. reg_w1(gspca_dev, 0x01, 0x22);
  1320. msleep(100);
  1321. reg_w1(gspca_dev, 0x01, 0x62);
  1322. reg_w1(gspca_dev, 0x17, 0x64);
  1323. reg_w1(gspca_dev, 0x17, 0x64);
  1324. reg_w1(gspca_dev, 0x01, 0x42);
  1325. msleep(10);
  1326. reg_w1(gspca_dev, 0x01, 0x42);
  1327. i2c_w8(gspca_dev, om6802_init0[0]);
  1328. i2c_w8(gspca_dev, om6802_init0[1]);
  1329. msleep(15);
  1330. reg_w1(gspca_dev, 0x02, 0x71);
  1331. msleep(150);
  1332. break;
  1333. case SENSOR_OV7630:
  1334. reg_w1(gspca_dev, 0x01, 0x61);
  1335. reg_w1(gspca_dev, 0x17, 0xe2);
  1336. reg_w1(gspca_dev, 0x01, 0x60);
  1337. reg_w1(gspca_dev, 0x01, 0x40);
  1338. break;
  1339. case SENSOR_OV7648:
  1340. reg_w1(gspca_dev, 0x01, 0x63);
  1341. reg_w1(gspca_dev, 0x17, 0x20);
  1342. reg_w1(gspca_dev, 0x01, 0x62);
  1343. reg_w1(gspca_dev, 0x01, 0x42);
  1344. break;
  1345. case SENSOR_PO1030:
  1346. reg_w1(gspca_dev, 0x01, 0x61);
  1347. reg_w1(gspca_dev, 0x17, 0x20);
  1348. reg_w1(gspca_dev, 0x01, 0x60);
  1349. reg_w1(gspca_dev, 0x01, 0x40);
  1350. break;
  1351. case SENSOR_OV7660:
  1352. /* fall thru */
  1353. case SENSOR_SP80708:
  1354. reg_w1(gspca_dev, 0x01, 0x63);
  1355. reg_w1(gspca_dev, 0x17, 0x20);
  1356. reg_w1(gspca_dev, 0x01, 0x62);
  1357. reg_w1(gspca_dev, 0x01, 0x42);
  1358. msleep(100);
  1359. reg_w1(gspca_dev, 0x02, 0x62);
  1360. break;
  1361. default:
  1362. /* case SENSOR_HV7131R: */
  1363. /* case SENSOR_MI0360: */
  1364. /* case SENSOR_MO4000: */
  1365. reg_w1(gspca_dev, 0x01, 0x43);
  1366. reg_w1(gspca_dev, 0x17, 0x61);
  1367. reg_w1(gspca_dev, 0x01, 0x42);
  1368. if (sd->sensor == SENSOR_HV7131R
  1369. && sd->bridge == BRIDGE_SN9C102P)
  1370. hv7131r_probe(gspca_dev);
  1371. break;
  1372. }
  1373. }
  1374. /* this function is called at probe time */
  1375. static int sd_config(struct gspca_dev *gspca_dev,
  1376. const struct usb_device_id *id)
  1377. {
  1378. struct sd *sd = (struct sd *) gspca_dev;
  1379. struct cam *cam;
  1380. sd->bridge = id->driver_info >> 16;
  1381. sd->sensor = id->driver_info;
  1382. cam = &gspca_dev->cam;
  1383. if (sd->sensor == SENSOR_ADCM1700) {
  1384. cam->cam_mode = cif_mode;
  1385. cam->nmodes = ARRAY_SIZE(cif_mode);
  1386. } else {
  1387. cam->cam_mode = vga_mode;
  1388. cam->nmodes = ARRAY_SIZE(vga_mode);
  1389. }
  1390. cam->npkt = 24; /* 24 packets per ISOC message */
  1391. sd->brightness = BRIGHTNESS_DEF;
  1392. sd->contrast = CONTRAST_DEF;
  1393. sd->colors = COLOR_DEF;
  1394. sd->blue = BLUE_BALANCE_DEF;
  1395. sd->red = RED_BALANCE_DEF;
  1396. sd->gamma = GAMMA_DEF;
  1397. sd->autogain = AUTOGAIN_DEF;
  1398. sd->ag_cnt = -1;
  1399. sd->vflip = VFLIP_DEF;
  1400. switch (sd->sensor) {
  1401. case SENSOR_OM6802:
  1402. sd->sharpness = 0x10;
  1403. break;
  1404. default:
  1405. sd->sharpness = SHARPNESS_DEF;
  1406. break;
  1407. }
  1408. sd->infrared = INFRARED_DEF;
  1409. sd->freq = FREQ_DEF;
  1410. sd->quality = QUALITY_DEF;
  1411. sd->jpegqual = 80;
  1412. return 0;
  1413. }
  1414. /* this function is called at probe and resume time */
  1415. static int sd_init(struct gspca_dev *gspca_dev)
  1416. {
  1417. struct sd *sd = (struct sd *) gspca_dev;
  1418. const u8 *sn9c1xx;
  1419. u8 regGpio[] = { 0x29, 0x74 };
  1420. u8 regF1;
  1421. /* setup a selector by bridge */
  1422. reg_w1(gspca_dev, 0xf1, 0x01);
  1423. reg_r(gspca_dev, 0x00, 1);
  1424. reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
  1425. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1426. regF1 = gspca_dev->usb_buf[0];
  1427. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  1428. switch (sd->bridge) {
  1429. case BRIDGE_SN9C102P:
  1430. if (regF1 != 0x11)
  1431. return -ENODEV;
  1432. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1433. break;
  1434. case BRIDGE_SN9C105:
  1435. if (regF1 != 0x11)
  1436. return -ENODEV;
  1437. if (sd->sensor == SENSOR_MI0360)
  1438. mi0360_probe(gspca_dev);
  1439. reg_w(gspca_dev, 0x01, regGpio, 2);
  1440. break;
  1441. case BRIDGE_SN9C120:
  1442. if (regF1 != 0x12)
  1443. return -ENODEV;
  1444. switch (sd->sensor) {
  1445. case SENSOR_MI0360:
  1446. mi0360_probe(gspca_dev);
  1447. break;
  1448. case SENSOR_OV7648:
  1449. ov7648_probe(gspca_dev);
  1450. break;
  1451. }
  1452. regGpio[1] = 0x70;
  1453. reg_w(gspca_dev, 0x01, regGpio, 2);
  1454. break;
  1455. default:
  1456. /* case BRIDGE_SN9C110: */
  1457. /* case BRIDGE_SN9C325: */
  1458. if (regF1 != 0x12)
  1459. return -ENODEV;
  1460. reg_w1(gspca_dev, 0x02, 0x62);
  1461. break;
  1462. }
  1463. reg_w1(gspca_dev, 0xf1, 0x01);
  1464. /* set the i2c address */
  1465. sn9c1xx = sn_tb[sd->sensor];
  1466. sd->i2c_addr = sn9c1xx[9];
  1467. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  1468. return 0;
  1469. }
  1470. static u32 setexposure(struct gspca_dev *gspca_dev,
  1471. u32 expo)
  1472. {
  1473. struct sd *sd = (struct sd *) gspca_dev;
  1474. switch (sd->sensor) {
  1475. case SENSOR_HV7131R: {
  1476. u8 Expodoit[] =
  1477. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1478. Expodoit[3] = expo >> 16;
  1479. Expodoit[4] = expo >> 8;
  1480. Expodoit[5] = expo;
  1481. i2c_w8(gspca_dev, Expodoit);
  1482. break;
  1483. }
  1484. case SENSOR_MI0360: {
  1485. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1486. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1487. static const u8 doit[] = /* update sensor */
  1488. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1489. static const u8 sensorgo[] = /* sensor on */
  1490. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1491. if (expo > 0x0635)
  1492. expo = 0x0635;
  1493. else if (expo < 0x0001)
  1494. expo = 0x0001;
  1495. expoMi[3] = expo >> 8;
  1496. expoMi[4] = expo;
  1497. i2c_w8(gspca_dev, expoMi);
  1498. i2c_w8(gspca_dev, doit);
  1499. i2c_w8(gspca_dev, sensorgo);
  1500. break;
  1501. }
  1502. case SENSOR_MO4000: {
  1503. u8 expoMof[] =
  1504. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1505. u8 expoMo10[] =
  1506. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1507. static const u8 gainMo[] =
  1508. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1509. if (expo > 0x1fff)
  1510. expo = 0x1fff;
  1511. else if (expo < 0x0001)
  1512. expo = 0x0001;
  1513. expoMof[3] = (expo & 0x03fc) >> 2;
  1514. i2c_w8(gspca_dev, expoMof);
  1515. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1516. | ((expo & 0x0003) << 4);
  1517. i2c_w8(gspca_dev, expoMo10);
  1518. i2c_w8(gspca_dev, gainMo);
  1519. PDEBUG(D_FRAM, "set exposure %d",
  1520. ((expoMo10[3] & 0x07) << 10)
  1521. | (expoMof[3] << 2)
  1522. | ((expoMo10[3] & 0x30) >> 4));
  1523. break;
  1524. }
  1525. case SENSOR_MT9V111: {
  1526. u8 expo_c1[] =
  1527. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1528. if (expo > 0x0280)
  1529. expo = 0x0280;
  1530. else if (expo < 0x0040)
  1531. expo = 0x0040;
  1532. expo_c1[3] = expo >> 8;
  1533. expo_c1[4] = expo;
  1534. i2c_w8(gspca_dev, expo_c1);
  1535. break;
  1536. }
  1537. case SENSOR_OM6802: {
  1538. u8 gainOm[] =
  1539. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1540. /* preset AGC - works when AutoExpo = off */
  1541. if (expo > 0x03ff)
  1542. expo = 0x03ff;
  1543. if (expo < 0x0001)
  1544. expo = 0x0001;
  1545. gainOm[3] = expo >> 2;
  1546. i2c_w8(gspca_dev, gainOm);
  1547. reg_w1(gspca_dev, 0x96, expo >> 5);
  1548. PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
  1549. break;
  1550. }
  1551. }
  1552. return expo;
  1553. }
  1554. static void setbrightness(struct gspca_dev *gspca_dev)
  1555. {
  1556. struct sd *sd = (struct sd *) gspca_dev;
  1557. unsigned int expo;
  1558. u8 k2;
  1559. k2 = ((int) sd->brightness - 0x8000) >> 10;
  1560. switch (sd->sensor) {
  1561. case SENSOR_ADCM1700:
  1562. if (k2 > 0x1f)
  1563. k2 = 0; /* only positive Y offset */
  1564. break;
  1565. case SENSOR_HV7131R:
  1566. expo = sd->brightness << 4;
  1567. if (expo > 0x002dc6c0)
  1568. expo = 0x002dc6c0;
  1569. else if (expo < 0x02a0)
  1570. expo = 0x02a0;
  1571. sd->exposure = setexposure(gspca_dev, expo);
  1572. break;
  1573. case SENSOR_MI0360:
  1574. case SENSOR_MO4000:
  1575. expo = sd->brightness >> 4;
  1576. sd->exposure = setexposure(gspca_dev, expo);
  1577. break;
  1578. case SENSOR_MT9V111:
  1579. expo = sd->brightness >> 8;
  1580. sd->exposure = setexposure(gspca_dev, expo);
  1581. return; /* don't set the Y offset */
  1582. case SENSOR_OM6802:
  1583. expo = sd->brightness >> 6;
  1584. sd->exposure = setexposure(gspca_dev, expo);
  1585. k2 = sd->brightness >> 11;
  1586. break;
  1587. }
  1588. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1589. }
  1590. static void setcontrast(struct gspca_dev *gspca_dev)
  1591. {
  1592. struct sd *sd = (struct sd *) gspca_dev;
  1593. u8 k2;
  1594. u8 contrast[6];
  1595. k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
  1596. contrast[0] = (k2 + 1) / 2; /* red */
  1597. contrast[1] = 0;
  1598. contrast[2] = k2; /* green */
  1599. contrast[3] = 0;
  1600. contrast[4] = (k2 + 1) / 5; /* blue */
  1601. contrast[5] = 0;
  1602. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1603. }
  1604. static void setcolors(struct gspca_dev *gspca_dev)
  1605. {
  1606. struct sd *sd = (struct sd *) gspca_dev;
  1607. int i, v;
  1608. u8 reg8a[12]; /* U & V gains */
  1609. static s16 uv[6] = { /* same as reg84 in signed decimal */
  1610. -24, -38, 64, /* UR UG UB */
  1611. 62, -51, -9 /* VR VG VB */
  1612. };
  1613. for (i = 0; i < 6; i++) {
  1614. v = uv[i] * sd->colors / COLOR_DEF;
  1615. reg8a[i * 2] = v;
  1616. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  1617. }
  1618. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  1619. }
  1620. static void setredblue(struct gspca_dev *gspca_dev)
  1621. {
  1622. struct sd *sd = (struct sd *) gspca_dev;
  1623. reg_w1(gspca_dev, 0x05, sd->red);
  1624. /* reg_w1(gspca_dev, 0x07, 32); */
  1625. reg_w1(gspca_dev, 0x06, sd->blue);
  1626. }
  1627. static void setgamma(struct gspca_dev *gspca_dev)
  1628. {
  1629. struct sd *sd = (struct sd *) gspca_dev;
  1630. int i;
  1631. u8 gamma[17];
  1632. const u8 *gamma_base;
  1633. static const u8 delta[17] = {
  1634. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  1635. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  1636. };
  1637. switch (sd->sensor) {
  1638. case SENSOR_ADCM1700:
  1639. gamma_base = gamma_spec_0;
  1640. break;
  1641. case SENSOR_HV7131R:
  1642. case SENSOR_MT9V111:
  1643. gamma_base = gamma_spec_1;
  1644. break;
  1645. case SENSOR_SP80708:
  1646. gamma_base = gamma_spec_2;
  1647. break;
  1648. default:
  1649. gamma_base = gamma_def;
  1650. break;
  1651. }
  1652. for (i = 0; i < sizeof gamma; i++)
  1653. gamma[i] = gamma_base[i]
  1654. + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
  1655. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  1656. }
  1657. static void setautogain(struct gspca_dev *gspca_dev)
  1658. {
  1659. struct sd *sd = (struct sd *) gspca_dev;
  1660. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
  1661. return;
  1662. switch (sd->sensor) {
  1663. case SENSOR_OV7630:
  1664. case SENSOR_OV7648: {
  1665. u8 comb;
  1666. if (sd->sensor == SENSOR_OV7630)
  1667. comb = 0xc0;
  1668. else
  1669. comb = 0xa0;
  1670. if (sd->autogain)
  1671. comb |= 0x03;
  1672. i2c_w1(&sd->gspca_dev, 0x13, comb);
  1673. return;
  1674. }
  1675. }
  1676. if (sd->autogain)
  1677. sd->ag_cnt = AG_CNT_START;
  1678. else
  1679. sd->ag_cnt = -1;
  1680. }
  1681. /* hv7131r/ov7630/ov7648 only */
  1682. static void setvflip(struct sd *sd)
  1683. {
  1684. u8 comn;
  1685. if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX))
  1686. return;
  1687. switch (sd->sensor) {
  1688. case SENSOR_HV7131R:
  1689. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  1690. if (sd->vflip)
  1691. comn |= 0x01;
  1692. i2c_w1(&sd->gspca_dev, 0x01, comn); /* sctra */
  1693. break;
  1694. case SENSOR_OV7630:
  1695. comn = 0x02;
  1696. if (!sd->vflip)
  1697. comn |= 0x80;
  1698. i2c_w1(&sd->gspca_dev, 0x75, comn);
  1699. break;
  1700. default:
  1701. /* case SENSOR_OV7648: */
  1702. comn = 0x06;
  1703. if (sd->vflip)
  1704. comn |= 0x80;
  1705. i2c_w1(&sd->gspca_dev, 0x75, comn);
  1706. break;
  1707. }
  1708. }
  1709. static void setsharpness(struct sd *sd)
  1710. {
  1711. reg_w1(&sd->gspca_dev, 0x99, sd->sharpness);
  1712. }
  1713. static void setinfrared(struct sd *sd)
  1714. {
  1715. if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX))
  1716. return;
  1717. /*fixme: different sequence for StarCam Clip and StarCam 370i */
  1718. /* Clip */
  1719. i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
  1720. sd->infrared ? 0x66 : 0x64);
  1721. }
  1722. static void setfreq(struct gspca_dev *gspca_dev)
  1723. {
  1724. struct sd *sd = (struct sd *) gspca_dev;
  1725. if (gspca_dev->ctrl_dis & (1 << FREQ_IDX))
  1726. return;
  1727. if (sd->sensor == SENSOR_OV7660) {
  1728. u8 com8;
  1729. com8 = 0xdf; /* auto gain/wb/expo */
  1730. switch (sd->freq) {
  1731. case 0: /* Banding filter disabled */
  1732. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  1733. break;
  1734. case 1: /* 50 hz */
  1735. i2c_w1(gspca_dev, 0x13, com8);
  1736. i2c_w1(gspca_dev, 0x3b, 0x0a);
  1737. break;
  1738. case 2: /* 60 hz */
  1739. i2c_w1(gspca_dev, 0x13, com8);
  1740. i2c_w1(gspca_dev, 0x3b, 0x02);
  1741. break;
  1742. }
  1743. } else {
  1744. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  1745. /* Get reg2a / reg2d base values */
  1746. switch (sd->sensor) {
  1747. case SENSOR_OV7630:
  1748. reg2a = 0x08;
  1749. reg2d = 0x01;
  1750. break;
  1751. case SENSOR_OV7648:
  1752. reg2a = 0x11;
  1753. reg2d = 0x81;
  1754. break;
  1755. }
  1756. switch (sd->freq) {
  1757. case 0: /* Banding filter disabled */
  1758. break;
  1759. case 1: /* 50 hz (filter on and framerate adj) */
  1760. reg2a |= 0x80;
  1761. reg2b = 0xac;
  1762. reg2d |= 0x04;
  1763. break;
  1764. case 2: /* 60 hz (filter on, no framerate adj) */
  1765. reg2a |= 0x80;
  1766. reg2d |= 0x04;
  1767. break;
  1768. }
  1769. i2c_w1(gspca_dev, 0x2a, reg2a);
  1770. i2c_w1(gspca_dev, 0x2b, reg2b);
  1771. i2c_w1(gspca_dev, 0x2d, reg2d);
  1772. }
  1773. }
  1774. static void setjpegqual(struct gspca_dev *gspca_dev)
  1775. {
  1776. struct sd *sd = (struct sd *) gspca_dev;
  1777. int i, sc;
  1778. if (sd->jpegqual < 50)
  1779. sc = 5000 / sd->jpegqual;
  1780. else
  1781. sc = 200 - sd->jpegqual * 2;
  1782. #if USB_BUF_SZ < 64
  1783. #error "No room enough in usb_buf for quantization table"
  1784. #endif
  1785. for (i = 0; i < 64; i++)
  1786. gspca_dev->usb_buf[i] =
  1787. (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
  1788. usb_control_msg(gspca_dev->dev,
  1789. usb_sndctrlpipe(gspca_dev->dev, 0),
  1790. 0x08,
  1791. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1792. 0x0100, 0,
  1793. gspca_dev->usb_buf, 64,
  1794. 500);
  1795. for (i = 0; i < 64; i++)
  1796. gspca_dev->usb_buf[i] =
  1797. (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
  1798. usb_control_msg(gspca_dev->dev,
  1799. usb_sndctrlpipe(gspca_dev->dev, 0),
  1800. 0x08,
  1801. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1802. 0x0140, 0,
  1803. gspca_dev->usb_buf, 64,
  1804. 500);
  1805. sd->reg18 ^= 0x40;
  1806. reg_w1(gspca_dev, 0x18, sd->reg18);
  1807. }
  1808. /* -- start the camera -- */
  1809. static int sd_start(struct gspca_dev *gspca_dev)
  1810. {
  1811. struct sd *sd = (struct sd *) gspca_dev;
  1812. int i;
  1813. u8 reg1, reg2, reg17;
  1814. const u8 *sn9c1xx;
  1815. const u8 (*init)[8];
  1816. int mode;
  1817. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  1818. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  1819. static const u8 CA_adcm1700[] =
  1820. { 0x14, 0xec, 0x0a, 0xf6 };
  1821. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  1822. static const u8 CE_ov76xx[] =
  1823. { 0x32, 0xdd, 0x32, 0xdd };
  1824. /* create the JPEG header */
  1825. sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
  1826. if (!sd->jpeg_hdr)
  1827. return -ENOMEM;
  1828. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  1829. 0x21); /* JPEG 422 */
  1830. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1831. /* initialize the bridge */
  1832. sn9c1xx = sn_tb[sd->sensor];
  1833. bridge_init(gspca_dev, sn9c1xx);
  1834. /* initialize the sensor */
  1835. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  1836. switch (sd->sensor) {
  1837. case SENSOR_ADCM1700:
  1838. reg2 = 0x60;
  1839. break;
  1840. case SENSOR_OM6802:
  1841. reg2 = 0x71;
  1842. break;
  1843. case SENSOR_SP80708:
  1844. reg2 = 0x62;
  1845. break;
  1846. default:
  1847. reg2 = 0x40;
  1848. break;
  1849. }
  1850. reg_w1(gspca_dev, 0x02, reg2);
  1851. reg_w1(gspca_dev, 0x02, reg2);
  1852. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  1853. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  1854. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  1855. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  1856. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  1857. if (sd->sensor == SENSOR_ADCM1700) {
  1858. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  1859. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  1860. } else {
  1861. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  1862. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  1863. }
  1864. reg_w1(gspca_dev, 0xc6, 0x00);
  1865. reg_w1(gspca_dev, 0xc7, 0x00);
  1866. if (sd->sensor == SENSOR_ADCM1700) {
  1867. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  1868. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  1869. } else {
  1870. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  1871. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  1872. }
  1873. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  1874. switch (sd->sensor) {
  1875. case SENSOR_MT9V111:
  1876. reg17 = 0xe0;
  1877. break;
  1878. case SENSOR_ADCM1700:
  1879. case SENSOR_OV7630:
  1880. reg17 = 0xe2;
  1881. break;
  1882. case SENSOR_OV7648:
  1883. reg17 = 0x20;
  1884. break;
  1885. case SENSOR_OV7660:
  1886. reg17 = 0xa0;
  1887. break;
  1888. case SENSOR_PO1030:
  1889. reg17 = 0xa0;
  1890. break;
  1891. default:
  1892. reg17 = 0x60;
  1893. break;
  1894. }
  1895. reg_w1(gspca_dev, 0x17, reg17);
  1896. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  1897. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  1898. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  1899. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  1900. setgamma(gspca_dev);
  1901. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  1902. for (i = 0; i < 8; i++)
  1903. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  1904. switch (sd->sensor) {
  1905. case SENSOR_ADCM1700:
  1906. case SENSOR_OV7660:
  1907. case SENSOR_SP80708:
  1908. reg_w1(gspca_dev, 0x9a, 0x05);
  1909. break;
  1910. case SENSOR_MT9V111:
  1911. reg_w1(gspca_dev, 0x9a, 0x07);
  1912. break;
  1913. case SENSOR_OV7648:
  1914. reg_w1(gspca_dev, 0x9a, 0x0a);
  1915. break;
  1916. default:
  1917. reg_w1(gspca_dev, 0x9a, 0x08);
  1918. break;
  1919. }
  1920. setsharpness(sd);
  1921. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  1922. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  1923. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  1924. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  1925. init = NULL;
  1926. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1927. if (mode)
  1928. reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
  1929. else
  1930. reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
  1931. reg17 = 0x61; /* 0x:20: enable sensor clock */
  1932. switch (sd->sensor) {
  1933. case SENSOR_ADCM1700:
  1934. init = adcm1700_sensor_param1;
  1935. reg1 = 0x46;
  1936. reg17 = 0xe2;
  1937. break;
  1938. case SENSOR_MO4000:
  1939. if (mode) {
  1940. /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
  1941. reg1 = 0x06; /* clk 24Mz */
  1942. } else {
  1943. reg17 = 0x22; /* 640 MCKSIZE */
  1944. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  1945. }
  1946. break;
  1947. case SENSOR_MT9V111:
  1948. init = mt9v111_sensor_param1;
  1949. if (mode) {
  1950. reg1 = 0x04; /* 320 clk 48Mhz */
  1951. } else {
  1952. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  1953. reg17 = 0xc2;
  1954. }
  1955. break;
  1956. case SENSOR_OM6802:
  1957. init = om6802_sensor_param1;
  1958. reg17 = 0x64; /* 640 MCKSIZE */
  1959. break;
  1960. case SENSOR_OV7630:
  1961. setvflip(sd);
  1962. reg17 = 0xe2;
  1963. reg1 = 0x44;
  1964. break;
  1965. case SENSOR_OV7648:
  1966. init = ov7648_sensor_param1;
  1967. reg17 = 0x21;
  1968. /* reg1 = 0x42; * 42 - 46? */
  1969. break;
  1970. case SENSOR_OV7660:
  1971. init = ov7660_sensor_param1;
  1972. if (sd->bridge == BRIDGE_SN9C120) {
  1973. if (mode) { /* 320x240 - 160x120 */
  1974. reg17 = 0xa2;
  1975. reg1 = 0x44; /* 48 Mhz, video trf eneble */
  1976. }
  1977. } else {
  1978. reg17 = 0x22;
  1979. reg1 = 0x06; /* 24 Mhz, video trf eneble
  1980. * inverse power down */
  1981. }
  1982. break;
  1983. case SENSOR_PO1030:
  1984. init = po1030_sensor_param1;
  1985. reg17 = 0xa2;
  1986. reg1 = 0x44;
  1987. break;
  1988. default:
  1989. /* case SENSOR_SP80708: */
  1990. init = sp80708_sensor_param1;
  1991. if (mode) {
  1992. /*?? reg1 = 0x04; * 320 clk 48Mhz */
  1993. } else {
  1994. reg1 = 0x46; /* 640 clk 48Mz */
  1995. reg17 = 0xa2;
  1996. }
  1997. break;
  1998. }
  1999. /* more sensor initialization - param1 */
  2000. if (init != NULL) {
  2001. i2c_w_seq(gspca_dev, init);
  2002. /* init = NULL; */
  2003. }
  2004. reg_w(gspca_dev, 0xc0, C0, 6);
  2005. if (sd->sensor == SENSOR_ADCM1700)
  2006. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2007. else
  2008. reg_w(gspca_dev, 0xca, CA, 4);
  2009. switch (sd->sensor) {
  2010. case SENSOR_ADCM1700:
  2011. case SENSOR_OV7630:
  2012. case SENSOR_OV7648:
  2013. case SENSOR_OV7660:
  2014. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2015. break;
  2016. default:
  2017. reg_w(gspca_dev, 0xce, CE, 4);
  2018. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2019. break;
  2020. }
  2021. /* here change size mode 0 -> VGA; 1 -> CIF */
  2022. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2023. reg_w1(gspca_dev, 0x18, sd->reg18);
  2024. setjpegqual(gspca_dev);
  2025. reg_w1(gspca_dev, 0x17, reg17);
  2026. reg_w1(gspca_dev, 0x01, reg1);
  2027. switch (sd->sensor) {
  2028. case SENSOR_OV7630:
  2029. setvflip(sd);
  2030. break;
  2031. }
  2032. setbrightness(gspca_dev);
  2033. setcontrast(gspca_dev);
  2034. setautogain(gspca_dev);
  2035. setfreq(gspca_dev);
  2036. return 0;
  2037. }
  2038. static void sd_stopN(struct gspca_dev *gspca_dev)
  2039. {
  2040. struct sd *sd = (struct sd *) gspca_dev;
  2041. static const u8 stophv7131[] =
  2042. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2043. static const u8 stopmi0360[] =
  2044. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2045. static const u8 stopov7648[] =
  2046. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2047. u8 data;
  2048. const u8 *sn9c1xx;
  2049. data = 0x0b;
  2050. switch (sd->sensor) {
  2051. case SENSOR_HV7131R:
  2052. i2c_w8(gspca_dev, stophv7131);
  2053. data = 0x2b;
  2054. break;
  2055. case SENSOR_MI0360:
  2056. i2c_w8(gspca_dev, stopmi0360);
  2057. data = 0x29;
  2058. break;
  2059. case SENSOR_OV7648:
  2060. i2c_w8(gspca_dev, stopov7648);
  2061. /* fall thru */
  2062. case SENSOR_MT9V111:
  2063. case SENSOR_OV7630:
  2064. case SENSOR_PO1030:
  2065. data = 0x29;
  2066. break;
  2067. }
  2068. sn9c1xx = sn_tb[sd->sensor];
  2069. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2070. reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
  2071. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2072. reg_w1(gspca_dev, 0x01, data);
  2073. reg_w1(gspca_dev, 0xf1, 0x00);
  2074. }
  2075. static void sd_stop0(struct gspca_dev *gspca_dev)
  2076. {
  2077. struct sd *sd = (struct sd *) gspca_dev;
  2078. kfree(sd->jpeg_hdr);
  2079. }
  2080. static void do_autogain(struct gspca_dev *gspca_dev)
  2081. {
  2082. struct sd *sd = (struct sd *) gspca_dev;
  2083. int delta;
  2084. int expotimes;
  2085. u8 luma_mean = 130;
  2086. u8 luma_delta = 20;
  2087. /* Thanks S., without your advice, autobright should not work :) */
  2088. if (sd->ag_cnt < 0)
  2089. return;
  2090. if (--sd->ag_cnt >= 0)
  2091. return;
  2092. sd->ag_cnt = AG_CNT_START;
  2093. delta = atomic_read(&sd->avg_lum);
  2094. PDEBUG(D_FRAM, "mean lum %d", delta);
  2095. if (delta < luma_mean - luma_delta ||
  2096. delta > luma_mean + luma_delta) {
  2097. switch (sd->sensor) {
  2098. case SENSOR_HV7131R:
  2099. expotimes = sd->exposure >> 8;
  2100. expotimes += (luma_mean - delta) >> 4;
  2101. if (expotimes < 0)
  2102. expotimes = 0;
  2103. sd->exposure = setexposure(gspca_dev,
  2104. (unsigned int) (expotimes << 8));
  2105. break;
  2106. case SENSOR_OM6802:
  2107. expotimes = sd->exposure;
  2108. expotimes += (luma_mean - delta) >> 2;
  2109. if (expotimes < 0)
  2110. expotimes = 0;
  2111. sd->exposure = setexposure(gspca_dev,
  2112. (unsigned int) expotimes);
  2113. setredblue(gspca_dev);
  2114. break;
  2115. default:
  2116. /* case SENSOR_MO4000: */
  2117. /* case SENSOR_MI0360: */
  2118. /* case SENSOR_MT9V111: */
  2119. expotimes = sd->exposure;
  2120. expotimes += (luma_mean - delta) >> 6;
  2121. if (expotimes < 0)
  2122. expotimes = 0;
  2123. sd->exposure = setexposure(gspca_dev,
  2124. (unsigned int) expotimes);
  2125. setredblue(gspca_dev);
  2126. break;
  2127. }
  2128. }
  2129. }
  2130. /* scan the URB packets */
  2131. /* This function is run at interrupt level. */
  2132. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2133. u8 *data, /* isoc packet */
  2134. int len) /* iso packet length */
  2135. {
  2136. struct sd *sd = (struct sd *) gspca_dev;
  2137. int sof, avg_lum;
  2138. sof = len - 64;
  2139. if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
  2140. /* end of frame */
  2141. gspca_frame_add(gspca_dev, LAST_PACKET,
  2142. data, sof + 2);
  2143. if (sd->ag_cnt < 0)
  2144. return;
  2145. /* w1 w2 w3 */
  2146. /* w4 w5 w6 */
  2147. /* w7 w8 */
  2148. /* w4 */
  2149. avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
  2150. /* w6 */
  2151. avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
  2152. /* w2 */
  2153. avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
  2154. /* w8 */
  2155. avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
  2156. /* w5 */
  2157. avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
  2158. avg_lum >>= 4;
  2159. atomic_set(&sd->avg_lum, avg_lum);
  2160. return;
  2161. }
  2162. if (gspca_dev->last_packet_type == LAST_PACKET) {
  2163. /* put the JPEG 422 header */
  2164. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2165. sd->jpeg_hdr, JPEG_HDR_SZ);
  2166. }
  2167. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2168. }
  2169. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  2170. {
  2171. struct sd *sd = (struct sd *) gspca_dev;
  2172. sd->brightness = val;
  2173. if (gspca_dev->streaming)
  2174. setbrightness(gspca_dev);
  2175. return 0;
  2176. }
  2177. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  2178. {
  2179. struct sd *sd = (struct sd *) gspca_dev;
  2180. *val = sd->brightness;
  2181. return 0;
  2182. }
  2183. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  2184. {
  2185. struct sd *sd = (struct sd *) gspca_dev;
  2186. sd->contrast = val;
  2187. if (gspca_dev->streaming)
  2188. setcontrast(gspca_dev);
  2189. return 0;
  2190. }
  2191. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  2192. {
  2193. struct sd *sd = (struct sd *) gspca_dev;
  2194. *val = sd->contrast;
  2195. return 0;
  2196. }
  2197. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  2198. {
  2199. struct sd *sd = (struct sd *) gspca_dev;
  2200. sd->colors = val;
  2201. if (gspca_dev->streaming)
  2202. setcolors(gspca_dev);
  2203. return 0;
  2204. }
  2205. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  2206. {
  2207. struct sd *sd = (struct sd *) gspca_dev;
  2208. *val = sd->colors;
  2209. return 0;
  2210. }
  2211. static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
  2212. {
  2213. struct sd *sd = (struct sd *) gspca_dev;
  2214. sd->blue = val;
  2215. if (gspca_dev->streaming)
  2216. setredblue(gspca_dev);
  2217. return 0;
  2218. }
  2219. static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
  2220. {
  2221. struct sd *sd = (struct sd *) gspca_dev;
  2222. *val = sd->blue;
  2223. return 0;
  2224. }
  2225. static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
  2226. {
  2227. struct sd *sd = (struct sd *) gspca_dev;
  2228. sd->red = val;
  2229. if (gspca_dev->streaming)
  2230. setredblue(gspca_dev);
  2231. return 0;
  2232. }
  2233. static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
  2234. {
  2235. struct sd *sd = (struct sd *) gspca_dev;
  2236. *val = sd->red;
  2237. return 0;
  2238. }
  2239. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  2240. {
  2241. struct sd *sd = (struct sd *) gspca_dev;
  2242. sd->gamma = val;
  2243. if (gspca_dev->streaming)
  2244. setgamma(gspca_dev);
  2245. return 0;
  2246. }
  2247. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  2248. {
  2249. struct sd *sd = (struct sd *) gspca_dev;
  2250. *val = sd->gamma;
  2251. return 0;
  2252. }
  2253. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  2254. {
  2255. struct sd *sd = (struct sd *) gspca_dev;
  2256. sd->autogain = val;
  2257. if (gspca_dev->streaming)
  2258. setautogain(gspca_dev);
  2259. return 0;
  2260. }
  2261. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  2262. {
  2263. struct sd *sd = (struct sd *) gspca_dev;
  2264. *val = sd->autogain;
  2265. return 0;
  2266. }
  2267. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  2268. {
  2269. struct sd *sd = (struct sd *) gspca_dev;
  2270. sd->sharpness = val;
  2271. if (gspca_dev->streaming)
  2272. setsharpness(sd);
  2273. return 0;
  2274. }
  2275. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  2276. {
  2277. struct sd *sd = (struct sd *) gspca_dev;
  2278. *val = sd->sharpness;
  2279. return 0;
  2280. }
  2281. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  2282. {
  2283. struct sd *sd = (struct sd *) gspca_dev;
  2284. sd->vflip = val;
  2285. if (gspca_dev->streaming)
  2286. setvflip(sd);
  2287. return 0;
  2288. }
  2289. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  2290. {
  2291. struct sd *sd = (struct sd *) gspca_dev;
  2292. *val = sd->vflip;
  2293. return 0;
  2294. }
  2295. static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
  2296. {
  2297. struct sd *sd = (struct sd *) gspca_dev;
  2298. sd->infrared = val;
  2299. if (gspca_dev->streaming)
  2300. setinfrared(sd);
  2301. return 0;
  2302. }
  2303. static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
  2304. {
  2305. struct sd *sd = (struct sd *) gspca_dev;
  2306. *val = sd->infrared;
  2307. return 0;
  2308. }
  2309. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  2310. {
  2311. struct sd *sd = (struct sd *) gspca_dev;
  2312. sd->freq = val;
  2313. if (gspca_dev->streaming)
  2314. setfreq(gspca_dev);
  2315. return 0;
  2316. }
  2317. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  2318. {
  2319. struct sd *sd = (struct sd *) gspca_dev;
  2320. *val = sd->freq;
  2321. return 0;
  2322. }
  2323. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  2324. struct v4l2_jpegcompression *jcomp)
  2325. {
  2326. struct sd *sd = (struct sd *) gspca_dev;
  2327. if (jcomp->quality < QUALITY_MIN)
  2328. sd->quality = QUALITY_MIN;
  2329. else if (jcomp->quality > QUALITY_MAX)
  2330. sd->quality = QUALITY_MAX;
  2331. else
  2332. sd->quality = jcomp->quality;
  2333. if (gspca_dev->streaming)
  2334. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2335. return 0;
  2336. }
  2337. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  2338. struct v4l2_jpegcompression *jcomp)
  2339. {
  2340. struct sd *sd = (struct sd *) gspca_dev;
  2341. memset(jcomp, 0, sizeof *jcomp);
  2342. jcomp->quality = sd->quality;
  2343. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  2344. | V4L2_JPEG_MARKER_DQT;
  2345. return 0;
  2346. }
  2347. static int sd_querymenu(struct gspca_dev *gspca_dev,
  2348. struct v4l2_querymenu *menu)
  2349. {
  2350. switch (menu->id) {
  2351. case V4L2_CID_POWER_LINE_FREQUENCY:
  2352. switch (menu->index) {
  2353. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  2354. strcpy((char *) menu->name, "NoFliker");
  2355. return 0;
  2356. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  2357. strcpy((char *) menu->name, "50 Hz");
  2358. return 0;
  2359. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  2360. strcpy((char *) menu->name, "60 Hz");
  2361. return 0;
  2362. }
  2363. break;
  2364. }
  2365. return -EINVAL;
  2366. }
  2367. /* sub-driver description */
  2368. static const struct sd_desc sd_desc = {
  2369. .name = MODULE_NAME,
  2370. .ctrls = sd_ctrls,
  2371. .nctrls = ARRAY_SIZE(sd_ctrls),
  2372. .config = sd_config,
  2373. .init = sd_init,
  2374. .start = sd_start,
  2375. .stopN = sd_stopN,
  2376. .stop0 = sd_stop0,
  2377. .pkt_scan = sd_pkt_scan,
  2378. .dq_callback = do_autogain,
  2379. .get_jcomp = sd_get_jcomp,
  2380. .set_jcomp = sd_set_jcomp,
  2381. .querymenu = sd_querymenu,
  2382. };
  2383. /* -- module initialisation -- */
  2384. #define BS(bridge, sensor) \
  2385. .driver_info = (BRIDGE_ ## bridge << 16) \
  2386. | SENSOR_ ## sensor
  2387. static const __devinitdata struct usb_device_id device_table[] = {
  2388. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2389. {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
  2390. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2391. #endif
  2392. {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)},
  2393. {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)},
  2394. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2395. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2396. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2397. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2398. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2399. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2400. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2401. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2402. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2403. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2404. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2405. {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
  2406. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2407. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2408. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2409. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2410. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2411. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2412. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2413. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2414. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2415. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2416. #endif
  2417. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2418. /* {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, P1030xC)}, */
  2419. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2420. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2421. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2422. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2423. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2424. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2425. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2426. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2427. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2428. /*bw600.inf:*/
  2429. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2430. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2431. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2432. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2433. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2434. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2435. #endif
  2436. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2437. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2438. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2439. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2440. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2441. #endif
  2442. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2443. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2444. /* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/
  2445. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2446. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2447. {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/
  2448. {}
  2449. };
  2450. MODULE_DEVICE_TABLE(usb, device_table);
  2451. /* -- device connect -- */
  2452. static int sd_probe(struct usb_interface *intf,
  2453. const struct usb_device_id *id)
  2454. {
  2455. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2456. THIS_MODULE);
  2457. }
  2458. static struct usb_driver sd_driver = {
  2459. .name = MODULE_NAME,
  2460. .id_table = device_table,
  2461. .probe = sd_probe,
  2462. .disconnect = gspca_disconnect,
  2463. #ifdef CONFIG_PM
  2464. .suspend = gspca_suspend,
  2465. .resume = gspca_resume,
  2466. #endif
  2467. };
  2468. /* -- module insert / remove -- */
  2469. static int __init sd_mod_init(void)
  2470. {
  2471. int ret;
  2472. ret = usb_register(&sd_driver);
  2473. if (ret < 0)
  2474. return ret;
  2475. info("registered");
  2476. return 0;
  2477. }
  2478. static void __exit sd_mod_exit(void)
  2479. {
  2480. usb_deregister(&sd_driver);
  2481. info("deregistered");
  2482. }
  2483. module_init(sd_mod_init);
  2484. module_exit(sd_mod_exit);