sonixj.c 67 KB

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