sonixj.c 67 KB

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