sonixj.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642
  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. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  26. MODULE_LICENSE("GPL");
  27. /* specific webcam descriptor */
  28. struct sd {
  29. struct gspca_dev gspca_dev; /* !! must be the first item */
  30. atomic_t avg_lum;
  31. unsigned int exposure;
  32. unsigned short brightness;
  33. unsigned char contrast;
  34. unsigned char colors;
  35. unsigned char autogain;
  36. signed char ag_cnt;
  37. #define AG_CNT_START 13
  38. char qindex;
  39. unsigned char bridge;
  40. #define BRIDGE_SN9C102P 0
  41. #define BRIDGE_SN9C105 1
  42. #define BRIDGE_SN9C110 2
  43. #define BRIDGE_SN9C120 3
  44. #define BRIDGE_SN9C325 4
  45. char sensor; /* Type of image sensor chip */
  46. #define SENSOR_HV7131R 0
  47. #define SENSOR_MI0360 1
  48. #define SENSOR_MO4000 2
  49. #define SENSOR_OM6802 3
  50. #define SENSOR_OV7630 4
  51. #define SENSOR_OV7648 5
  52. #define SENSOR_OV7660 6
  53. unsigned char i2c_base;
  54. };
  55. /* V4L2 controls supported by the driver */
  56. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  57. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  58. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  59. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  60. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  61. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  62. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  63. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  64. static struct ctrl sd_ctrls[] = {
  65. {
  66. {
  67. .id = V4L2_CID_BRIGHTNESS,
  68. .type = V4L2_CTRL_TYPE_INTEGER,
  69. .name = "Brightness",
  70. .minimum = 0,
  71. #define BRIGHTNESS_MAX 0xffff
  72. .maximum = BRIGHTNESS_MAX,
  73. .step = 1,
  74. #define BRIGHTNESS_DEF 0x7fff
  75. .default_value = BRIGHTNESS_DEF,
  76. },
  77. .set = sd_setbrightness,
  78. .get = sd_getbrightness,
  79. },
  80. {
  81. {
  82. .id = V4L2_CID_CONTRAST,
  83. .type = V4L2_CTRL_TYPE_INTEGER,
  84. .name = "Contrast",
  85. .minimum = 0,
  86. #define CONTRAST_MAX 127
  87. .maximum = CONTRAST_MAX,
  88. .step = 1,
  89. #define CONTRAST_DEF 63
  90. .default_value = CONTRAST_DEF,
  91. },
  92. .set = sd_setcontrast,
  93. .get = sd_getcontrast,
  94. },
  95. {
  96. {
  97. .id = V4L2_CID_SATURATION,
  98. .type = V4L2_CTRL_TYPE_INTEGER,
  99. .name = "Color",
  100. .minimum = 0,
  101. .maximum = 64,
  102. .step = 1,
  103. #define COLOR_DEF 32
  104. .default_value = COLOR_DEF,
  105. },
  106. .set = sd_setcolors,
  107. .get = sd_getcolors,
  108. },
  109. #define AUTOGAIN_IDX 3
  110. {
  111. {
  112. .id = V4L2_CID_AUTOGAIN,
  113. .type = V4L2_CTRL_TYPE_BOOLEAN,
  114. .name = "Auto Gain",
  115. .minimum = 0,
  116. .maximum = 1,
  117. .step = 1,
  118. #define AUTOGAIN_DEF 1
  119. .default_value = AUTOGAIN_DEF,
  120. },
  121. .set = sd_setautogain,
  122. .get = sd_getautogain,
  123. },
  124. };
  125. static struct v4l2_pix_format vga_mode[] = {
  126. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  127. .bytesperline = 160,
  128. .sizeimage = 160 * 120 * 4 / 8 + 590,
  129. .colorspace = V4L2_COLORSPACE_JPEG,
  130. .priv = 2},
  131. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  132. .bytesperline = 320,
  133. .sizeimage = 320 * 240 * 3 / 8 + 590,
  134. .colorspace = V4L2_COLORSPACE_JPEG,
  135. .priv = 1},
  136. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  137. .bytesperline = 640,
  138. .sizeimage = 640 * 480 * 3 / 8 + 590,
  139. .colorspace = V4L2_COLORSPACE_JPEG,
  140. .priv = 0},
  141. };
  142. /*Data from sn9c102p+hv71331r */
  143. static const __u8 sn_hv7131[] = {
  144. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  145. 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
  146. /* reg8 reg9 rega regb regc regd rege regf */
  147. 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10,
  148. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  149. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  150. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  151. 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  152. };
  153. static const __u8 sn_mi0360[] = {
  154. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  155. 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
  156. /* reg8 reg9 rega regb regc regd rege regf */
  157. 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
  158. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  159. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  160. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  161. 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  162. };
  163. static const __u8 sn_mo4000[] = {
  164. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  165. 0x12, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  166. /* reg8 reg9 rega regb regc regd rege regf */
  167. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  168. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  169. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  170. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  171. 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  172. };
  173. static const __u8 sn_om6802[] = {
  174. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  175. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x34, 0x27, 0x20,
  176. /* reg8 reg9 rega regb regc regd rege regf */
  177. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  178. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  179. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  180. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  181. 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  182. 0x08, 0x22, 0x44, 0x63, 0x7d, 0x92, 0xa3, 0xaf,
  183. 0xbc, 0xc4, 0xcd, 0xd5, 0xdc, 0xe1, 0xe8, 0xef,
  184. 0xf7
  185. };
  186. static const __u8 sn_ov7630[] = {
  187. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  188. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
  189. /* reg8 reg9 rega regb regc regd rege regf */
  190. 0xa1, 0x21, 0x76, 0x21, 0x00, 0x00, 0x00, 0x10,
  191. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  192. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  193. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  194. 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00
  195. };
  196. static const __u8 sn_ov7648[] = {
  197. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  198. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  199. /* reg8 reg9 rega regb regc regd rege regf */
  200. 0xa1, 0x6e, 0x18, 0x65, 0x00, 0x00, 0x00, 0x10,
  201. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  202. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x82,
  203. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  204. 0x07, 0x00, 0x00, 0x00, 0x00, 0x00
  205. };
  206. static const __u8 sn_ov7660[] = {
  207. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  208. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  209. /* reg8 reg9 rega regb regc regd rege regf */
  210. 0x81, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
  211. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  212. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  213. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  214. 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  215. };
  216. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  217. static const __u8 *sn_tb[] = {
  218. sn_hv7131,
  219. sn_mi0360,
  220. sn_mo4000,
  221. sn_om6802,
  222. sn_ov7630,
  223. sn_ov7648,
  224. sn_ov7660
  225. };
  226. static const __u8 gamma_def[] = {
  227. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  228. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  229. };
  230. static const __u8 reg84[] = {
  231. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, 0xe5, 0x0f,
  232. 0xe4, 0x0f, 0x38, 0x00, 0x3e, 0x00, 0xc3, 0x0f,
  233. 0xf7, 0x0f, 0x00, 0x00, 0x00
  234. };
  235. static const __u8 hv7131r_sensor_init[][8] = {
  236. {0xC1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  237. {0xB1, 0x11, 0x34, 0x17, 0x7F, 0x00, 0x00, 0x10},
  238. {0xD1, 0x11, 0x40, 0xFF, 0x7F, 0x7F, 0x7F, 0x10},
  239. {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10},
  240. {0xD1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  241. {0xD1, 0x11, 0x14, 0x01, 0xE2, 0x02, 0x82, 0x10},
  242. {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  243. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  244. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  245. {0xC1, 0x11, 0x25, 0x00, 0x61, 0xA8, 0x00, 0x10},
  246. {0xA1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  247. {0xC1, 0x11, 0x31, 0x20, 0x2E, 0x20, 0x00, 0x10},
  248. {0xC1, 0x11, 0x25, 0x00, 0xC3, 0x50, 0x00, 0x10},
  249. {0xA1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  250. {0xC1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  251. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  252. {0xA1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  253. {0xA1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
  254. {0xA1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  255. {0xA1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  256. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  257. {0xA1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  258. {0xA1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
  259. {0xA1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  260. {0xA1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  261. {}
  262. };
  263. static const __u8 mi0360_sensor_init[][8] = {
  264. {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  265. {0xB1, 0x5D, 0x0D, 0x00, 0x01, 0x00, 0x00, 0x10},
  266. {0xB1, 0x5D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x10},
  267. {0xD1, 0x5D, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  268. {0xD1, 0x5D, 0x03, 0x01, 0xE2, 0x02, 0x82, 0x10},
  269. {0xD1, 0x5D, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  270. {0xB1, 0x5D, 0x0D, 0x00, 0x02, 0x00, 0x00, 0x10},
  271. {0xD1, 0x5D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x10},
  272. {0xD1, 0x5D, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x10},
  273. {0xD1, 0x5D, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x10},
  274. {0xD1, 0x5D, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  275. {0xD1, 0x5D, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  276. {0xD1, 0x5D, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  277. {0xD1, 0x5D, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  278. {0xD1, 0x5D, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  279. {0xD1, 0x5D, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x10},
  280. {0xD1, 0x5D, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x10},
  281. {0xB1, 0x5D, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  282. {0xD1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  283. {0xD1, 0x5D, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  284. {0xD1, 0x5D, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  285. {0xD1, 0x5D, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  286. {0xD1, 0x5D, 0x2F, 0xF7, 0xB0, 0x00, 0x04, 0x10},
  287. {0xD1, 0x5D, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  288. {0xD1, 0x5D, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  289. {0xB1, 0x5D, 0x3D, 0x06, 0x8F, 0x00, 0x00, 0x10},
  290. {0xD1, 0x5D, 0x40, 0x01, 0xE0, 0x00, 0xD1, 0x10},
  291. {0xB1, 0x5D, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  292. {0xD1, 0x5D, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  293. {0xD1, 0x5D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x10},
  294. {0xD1, 0x5D, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x10},
  295. {0xD1, 0x5D, 0x5E, 0x00, 0x00, 0xA3, 0x1D, 0x10},
  296. {0xB1, 0x5D, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  297. {0xB1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  298. {0xB1, 0x5D, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  299. {0xB1, 0x5D, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  300. {0xD1, 0x5D, 0x2B, 0x00, 0xA0, 0x00, 0xB0, 0x10},
  301. {0xD1, 0x5D, 0x2D, 0x00, 0xA0, 0x00, 0xA0, 0x10},
  302. {0xB1, 0x5D, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  303. {0xB1, 0x5D, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  304. {0xB1, 0x5D, 0x05, 0x00, 0x0A, 0x00, 0x00, 0x10},
  305. {0xB1, 0x5D, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  306. {0xD1, 0x5D, 0x2B, 0x00, 0xB9, 0x00, 0xE3, 0x10},
  307. {0xD1, 0x5D, 0x2D, 0x00, 0x5f, 0x00, 0xB9, 0x10}, /* 42 */
  308. /* {0xB1, 0x5D, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  309. /* {0xB1, 0x5D, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  310. {0xB1, 0x5D, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  311. {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  312. {}
  313. };
  314. static const __u8 mo4000_sensor_init[][8] = {
  315. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  316. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  317. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  318. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  319. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  320. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  321. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  322. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  323. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  324. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  325. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  326. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  327. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  328. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  329. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  330. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  331. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  332. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  333. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  334. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  335. {}
  336. };
  337. static __u8 om6802_sensor_init[][8] = {
  338. {0xa0, 0x34, 0x90, 0x05, 0x00, 0x00, 0x00, 0x10},
  339. {0xa0, 0x34, 0x49, 0x85, 0x00, 0x00, 0x00, 0x10},
  340. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  341. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  342. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  343. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  344. /* white balance & auto-exposure */
  345. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  346. * set color mode */
  347. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  348. * max AGC value in AE */
  349. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  350. * preset AGC */
  351. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  352. * preset brightness */
  353. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  354. * preset contrast */
  355. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  356. * preset gamma */
  357. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  358. /* luminance mode (0x4f = AE) */
  359. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  360. /* preset shutter */
  361. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  362. * auto frame rate */
  363. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  364. /* {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10}, */
  365. /* {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10}, */
  366. /* {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10}, */
  367. /* {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10}, */
  368. {}
  369. };
  370. static const __u8 ov7630_sensor_init[][8] = {
  371. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  372. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  373. /* win: delay 20ms */
  374. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  375. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  376. /* win: delay 20ms */
  377. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  378. /* win: i2c_r from 00 to 80 */
  379. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  380. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  381. {0xd1, 0x21, 0x11, 0x00, 0x48, 0xc0, 0x00, 0x10},
  382. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  383. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  384. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  385. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  386. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  387. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  388. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  389. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  390. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  391. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  392. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  393. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  394. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  395. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  396. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  397. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  398. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  399. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  400. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  401. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  402. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  403. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  404. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  405. /* */
  406. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  407. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  408. /*fixme: + 0x12, 0x04*/
  409. {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10},
  410. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  411. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  412. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  413. /* */
  414. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  415. {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10},
  416. {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10},
  417. /* */
  418. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  419. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  420. {}
  421. };
  422. static const __u8 ov7660_sensor_init[][8] = {
  423. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  424. /* (delay 20ms) */
  425. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  426. /* Outformat = rawRGB */
  427. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  428. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x74, 0x00, 0x10},
  429. /* GAIN BLUE RED VREF */
  430. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  431. /* COM 1 BAVE GEAVE AECHH */
  432. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  433. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  434. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  435. /* AECH CLKRC COM7 COM8 */
  436. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  437. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  438. /* HSTART HSTOP VSTRT VSTOP */
  439. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  440. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  441. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  442. /* BOS GBOS GROS ROS (BGGR offset) */
  443. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  444. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  445. /* AEW AEB VPT BBIAS */
  446. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  447. /* GbBIAS RSVD EXHCH EXHCL */
  448. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  449. /* RBIAS ADVFL ASDVFH YAVE */
  450. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  451. /* HSYST HSYEN HREF */
  452. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  453. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  454. /* ADC ACOM OFON TSLB */
  455. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  456. /* COM11 COM12 COM13 COM14 */
  457. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  458. /* EDGE COM15 COM16 COM17 */
  459. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  460. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  461. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  462. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  463. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  464. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  465. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  466. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  467. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  468. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  469. /* LCC1 LCC2 LCC3 LCC4 */
  470. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  471. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  472. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  473. /* band gap reference [0:3] DBLV */
  474. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  475. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  476. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  477. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  478. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  479. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  480. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  481. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  482. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  483. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  484. /****** (some exchanges in the win trace) ******/
  485. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  486. /* bits[3..0]reserved */
  487. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  488. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  489. /* VREF vertical frame ctrl */
  490. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  491. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  492. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  493. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  494. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  495. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  496. /****** (some exchanges in the win trace) ******/
  497. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  498. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  499. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  500. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  501. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  502. /****** (some exchanges in the win trace) ******/
  503. /******!! startsensor KO if changed !!****/
  504. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  505. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  506. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  507. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  508. {}
  509. };
  510. /* reg 0x04 reg 0x07 reg 0x10 */
  511. /* expo = (COM1 & 0x02) | ((AECHH & 0x2f) << 10) | (AECh << 2) */
  512. static const __u8 ov7648_sensor_init[][8] = {
  513. {0xC1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00},
  514. {0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00},
  515. {0xC1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00},
  516. {0xA1, 0x6E, 0x3F, 0x20, 0x00, 0x00, 0x00, 0x10},
  517. {0xA1, 0x6E, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x10},
  518. {0xA1, 0x6E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x10},
  519. {0xD1, 0x6E, 0x04, 0x02, 0xB1, 0x02, 0x39, 0x10},
  520. {0xD1, 0x6E, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  521. {0xD1, 0x6E, 0x0C, 0x02, 0x7F, 0x01, 0xE0, 0x10},
  522. {0xD1, 0x6E, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  523. {0xD1, 0x6E, 0x16, 0x85, 0x40, 0x4A, 0x40, 0x10},
  524. {0xC1, 0x6E, 0x1A, 0x00, 0x80, 0x00, 0x00, 0x10},
  525. {0xD1, 0x6E, 0x1D, 0x08, 0x03, 0x00, 0x00, 0x10},
  526. {0xD1, 0x6E, 0x23, 0x00, 0xB0, 0x00, 0x94, 0x10},
  527. {0xD1, 0x6E, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  528. {0xD1, 0x6E, 0x2D, 0x14, 0x35, 0x61, 0x84, 0x10},
  529. {0xD1, 0x6E, 0x31, 0xA2, 0xBD, 0xD8, 0xFF, 0x10},
  530. {0xD1, 0x6E, 0x35, 0x06, 0x1E, 0x12, 0x02, 0x10},
  531. {0xD1, 0x6E, 0x39, 0xAA, 0x53, 0x37, 0xD5, 0x10},
  532. {0xA1, 0x6E, 0x3D, 0xF2, 0x00, 0x00, 0x00, 0x10},
  533. {0xD1, 0x6E, 0x3E, 0x00, 0x00, 0x80, 0x03, 0x10},
  534. {0xD1, 0x6E, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  535. {0xC1, 0x6E, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  536. {0xD1, 0x6E, 0x4B, 0x02, 0xEF, 0x08, 0xCD, 0x10},
  537. {0xD1, 0x6E, 0x4F, 0x00, 0xD0, 0x00, 0xA0, 0x10},
  538. {0xD1, 0x6E, 0x53, 0x01, 0xAA, 0x01, 0x40, 0x10},
  539. {0xD1, 0x6E, 0x5A, 0x50, 0x04, 0x30, 0x03, 0x10},
  540. {0xA1, 0x6E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x10},
  541. {0xD1, 0x6E, 0x5F, 0x10, 0x40, 0xFF, 0x00, 0x10},
  542. /* {0xD1, 0x6E, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  543. {0xD1, 0x6E, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  544. * This is currently setting a
  545. * blue tint, and some things more , i leave it here for future test if
  546. * somene is having problems with color on this sensor
  547. {0xD1, 0x6E, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x10},
  548. {0xD1, 0x6E, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x10},
  549. {0xC1, 0x6E, 0x73, 0x10, 0x80, 0xEB, 0x00, 0x10},
  550. {0xA1, 0x6E, 0x1E, 0x03, 0x00, 0x00, 0x00, 0x10},
  551. {0xA1, 0x6E, 0x15, 0x01, 0x00, 0x00, 0x00, 0x10},
  552. {0xC1, 0x6E, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10},
  553. {0xA1, 0x6E, 0x1D, 0x08, 0x00, 0x00, 0x00, 0x10},
  554. {0xA1, 0x6E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  555. {0xA1, 0x6E, 0x07, 0xB5, 0x00, 0x00, 0x00, 0x10},
  556. {0xA1, 0x6E, 0x18, 0x6B, 0x00, 0x00, 0x00, 0x10},
  557. {0xA1, 0x6E, 0x1D, 0x08, 0x00, 0x00, 0x00, 0x10},
  558. {0xA1, 0x6E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  559. {0xA1, 0x6E, 0x07, 0xB8, 0x00, 0x00, 0x00, 0x10}, */
  560. {0xC1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00},
  561. {0xA1, 0x6E, 0x06, 0x03, 0x00, 0x00, 0x00, 0x10}, /* Bright... */
  562. {0xA1, 0x6E, 0x07, 0x66, 0x00, 0x00, 0x00, 0x10}, /* B.. */
  563. {0xC1, 0x6E, 0x1A, 0x03, 0x65, 0x90, 0x00, 0x10}, /* Bright/Witen....*/
  564. /* {0xC1, 0x6E, 0x16, 0x45, 0x40, 0x60, 0x00, 0x10}, * Bright/Witene */
  565. {}
  566. };
  567. static const __u8 qtable4[] = {
  568. 0x06, 0x04, 0x04, 0x06, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06, 0x08, 0x06,
  569. 0x06, 0x08, 0x0A, 0x11,
  570. 0x0A, 0x0A, 0x08, 0x08, 0x0A, 0x15, 0x0F, 0x0F, 0x0C, 0x11, 0x19, 0x15,
  571. 0x19, 0x19, 0x17, 0x15,
  572. 0x17, 0x17, 0x1B, 0x1D, 0x25, 0x21, 0x1B, 0x1D, 0x23, 0x1D, 0x17, 0x17,
  573. 0x21, 0x2E, 0x21, 0x23,
  574. 0x27, 0x29, 0x2C, 0x2C, 0x2C, 0x19, 0x1F, 0x30, 0x32, 0x2E, 0x29, 0x32,
  575. 0x25, 0x29, 0x2C, 0x29,
  576. 0x06, 0x08, 0x08, 0x0A, 0x08, 0x0A, 0x13, 0x0A, 0x0A, 0x13, 0x29, 0x1B,
  577. 0x17, 0x1B, 0x29, 0x29,
  578. 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29,
  579. 0x29, 0x29, 0x29, 0x29,
  580. 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29,
  581. 0x29, 0x29, 0x29, 0x29,
  582. 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29,
  583. 0x29, 0x29, 0x29, 0x29
  584. };
  585. /* read <len> bytes (len < sizeof gspca_dev->usb_buf) to gspca_dev->usb_buf */
  586. static void reg_r(struct gspca_dev *gspca_dev,
  587. __u16 value, int len)
  588. {
  589. usb_control_msg(gspca_dev->dev,
  590. usb_rcvctrlpipe(gspca_dev->dev, 0),
  591. 0,
  592. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  593. value, 0,
  594. gspca_dev->usb_buf, len,
  595. 500);
  596. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  597. }
  598. static void reg_w1(struct gspca_dev *gspca_dev,
  599. __u16 value,
  600. __u8 data)
  601. {
  602. PDEBUG(D_USBO, "reg_w1 [%02x] = %02x", value, data);
  603. gspca_dev->usb_buf[0] = data;
  604. usb_control_msg(gspca_dev->dev,
  605. usb_sndctrlpipe(gspca_dev->dev, 0),
  606. 0x08,
  607. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  608. value,
  609. 0,
  610. gspca_dev->usb_buf, 1,
  611. 500);
  612. }
  613. static void reg_w(struct gspca_dev *gspca_dev,
  614. __u16 value,
  615. const __u8 *buffer,
  616. int len)
  617. {
  618. PDEBUG(D_USBO, "reg_w [%02x] = %02x %02x ..",
  619. value, buffer[0], buffer[1]);
  620. if (len <= sizeof gspca_dev->usb_buf) {
  621. memcpy(gspca_dev->usb_buf, buffer, len);
  622. usb_control_msg(gspca_dev->dev,
  623. usb_sndctrlpipe(gspca_dev->dev, 0),
  624. 0x08,
  625. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  626. value, 0,
  627. gspca_dev->usb_buf, len,
  628. 500);
  629. } else {
  630. __u8 *tmpbuf;
  631. tmpbuf = kmalloc(len, GFP_KERNEL);
  632. memcpy(tmpbuf, buffer, len);
  633. usb_control_msg(gspca_dev->dev,
  634. usb_sndctrlpipe(gspca_dev->dev, 0),
  635. 0x08,
  636. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  637. value, 0,
  638. tmpbuf, len,
  639. 500);
  640. kfree(tmpbuf);
  641. }
  642. }
  643. /* I2C write 1 byte */
  644. static void i2c_w1(struct gspca_dev *gspca_dev, __u8 reg, __u8 val)
  645. {
  646. struct sd *sd = (struct sd *) gspca_dev;
  647. PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
  648. gspca_dev->usb_buf[0] = 0x81 | (2 << 4); /* = a1 */
  649. gspca_dev->usb_buf[1] = sd->i2c_base;
  650. gspca_dev->usb_buf[2] = reg;
  651. gspca_dev->usb_buf[3] = val;
  652. gspca_dev->usb_buf[4] = 0;
  653. gspca_dev->usb_buf[5] = 0;
  654. gspca_dev->usb_buf[6] = 0;
  655. gspca_dev->usb_buf[7] = 0x10;
  656. usb_control_msg(gspca_dev->dev,
  657. usb_sndctrlpipe(gspca_dev->dev, 0),
  658. 0x08,
  659. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  660. 0x08, /* value = i2c */
  661. 0,
  662. gspca_dev->usb_buf, 8,
  663. 500);
  664. }
  665. /* I2C write 8 bytes */
  666. static void i2c_w8(struct gspca_dev *gspca_dev,
  667. const __u8 *buffer)
  668. {
  669. memcpy(gspca_dev->usb_buf, buffer, 8);
  670. usb_control_msg(gspca_dev->dev,
  671. usb_sndctrlpipe(gspca_dev->dev, 0),
  672. 0x08,
  673. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  674. 0x08, 0, /* value, index */
  675. gspca_dev->usb_buf, 8,
  676. 500);
  677. }
  678. /* read 5 bytes in gspca_dev->usb_buf */
  679. static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg)
  680. {
  681. struct sd *sd = (struct sd *) gspca_dev;
  682. __u8 mode[8];
  683. mode[0] = 0x81 | 0x10;
  684. mode[1] = sd->i2c_base;
  685. mode[2] = reg;
  686. mode[3] = 0;
  687. mode[4] = 0;
  688. mode[5] = 0;
  689. mode[6] = 0;
  690. mode[7] = 0x10;
  691. i2c_w8(gspca_dev, mode);
  692. msleep(2);
  693. mode[0] = 0x81 | (5 << 4) | 0x02;
  694. mode[2] = 0;
  695. i2c_w8(gspca_dev, mode);
  696. msleep(2);
  697. reg_r(gspca_dev, 0x0a, 5);
  698. }
  699. static int probesensor(struct gspca_dev *gspca_dev)
  700. {
  701. struct sd *sd = (struct sd *) gspca_dev;
  702. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  703. msleep(10);
  704. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  705. msleep(10);
  706. i2c_r5(gspca_dev, 0); /* read sensor id */
  707. if (gspca_dev->usb_buf[0] == 0x02
  708. && gspca_dev->usb_buf[1] == 0x09
  709. && gspca_dev->usb_buf[2] == 0x01
  710. && gspca_dev->usb_buf[3] == 0x00
  711. && gspca_dev->usb_buf[4] == 0x00) {
  712. PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
  713. sd->sensor = SENSOR_HV7131R;
  714. return SENSOR_HV7131R;
  715. }
  716. PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
  717. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  718. gspca_dev->usb_buf[2]);
  719. PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
  720. return -ENODEV;
  721. }
  722. static int configure_gpio(struct gspca_dev *gspca_dev,
  723. const __u8 *sn9c1xx)
  724. {
  725. struct sd *sd = (struct sd *) gspca_dev;
  726. const __u8 *reg9a;
  727. static const __u8 reg9a_def[] =
  728. {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
  729. static const __u8 reg9a_sn9c325[] =
  730. {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
  731. static const __u8 regd4[] = {0x60, 0x00, 0x00};
  732. reg_w1(gspca_dev, 0xf1, 0x00);
  733. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  734. /* configure gpio */
  735. reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
  736. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  737. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm len was 3 */
  738. switch (sd->bridge) {
  739. case BRIDGE_SN9C325:
  740. reg9a = reg9a_sn9c325;
  741. break;
  742. default:
  743. reg9a = reg9a_def;
  744. break;
  745. }
  746. reg_w(gspca_dev, 0x9a, reg9a, 6);
  747. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4); /*fixme:jfm was 60 only*/
  748. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  749. switch (sd->sensor) {
  750. case SENSOR_OM6802:
  751. reg_w1(gspca_dev, 0x02, 0x71);
  752. reg_w1(gspca_dev, 0x01, 0x42);
  753. reg_w1(gspca_dev, 0x17, 0x64);
  754. reg_w1(gspca_dev, 0x01, 0x42);
  755. break;
  756. /*jfm: from win trace */
  757. case SENSOR_OV7630:
  758. reg_w1(gspca_dev, 0x01, 0x61);
  759. reg_w1(gspca_dev, 0x17, 0xe2);
  760. reg_w1(gspca_dev, 0x01, 0x60);
  761. reg_w1(gspca_dev, 0x01, 0x40);
  762. break;
  763. case SENSOR_OV7648:
  764. reg_w1(gspca_dev, 0x01, 0x43);
  765. reg_w1(gspca_dev, 0x17, 0xae);
  766. reg_w1(gspca_dev, 0x01, 0x42);
  767. break;
  768. /*jfm: from win trace */
  769. case SENSOR_OV7660:
  770. reg_w1(gspca_dev, 0x01, 0x61);
  771. reg_w1(gspca_dev, 0x17, 0x20);
  772. reg_w1(gspca_dev, 0x01, 0x60);
  773. reg_w1(gspca_dev, 0x01, 0x40);
  774. break;
  775. default:
  776. reg_w1(gspca_dev, 0x01, 0x43);
  777. reg_w1(gspca_dev, 0x17, 0x61);
  778. reg_w1(gspca_dev, 0x01, 0x42);
  779. if (sd->sensor == SENSOR_HV7131R) {
  780. if (probesensor(gspca_dev) < 0)
  781. return -ENODEV;
  782. }
  783. break;
  784. }
  785. return 0;
  786. }
  787. static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
  788. {
  789. int i = 0;
  790. static const __u8 SetSensorClk[] = /* 0x08 Mclk */
  791. { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
  792. while (hv7131r_sensor_init[i][0]) {
  793. i2c_w8(gspca_dev, hv7131r_sensor_init[i]);
  794. i++;
  795. }
  796. i2c_w8(gspca_dev, SetSensorClk);
  797. }
  798. static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
  799. {
  800. int i = 0;
  801. while (mi0360_sensor_init[i][0]) {
  802. i2c_w8(gspca_dev, mi0360_sensor_init[i]);
  803. i++;
  804. }
  805. }
  806. static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
  807. {
  808. int i = 0;
  809. while (mo4000_sensor_init[i][0]) {
  810. i2c_w8(gspca_dev, mo4000_sensor_init[i]);
  811. i++;
  812. }
  813. }
  814. static void om6802_InitSensor(struct gspca_dev *gspca_dev)
  815. {
  816. int i = 0;
  817. while (om6802_sensor_init[i][0]) {
  818. i2c_w8(gspca_dev, om6802_sensor_init[i]);
  819. i++;
  820. }
  821. }
  822. static void ov7630_InitSensor(struct gspca_dev *gspca_dev)
  823. {
  824. int i = 0;
  825. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 76 01 */
  826. i++;
  827. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 (RGB+SRST) */
  828. i++;
  829. msleep(20);
  830. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */
  831. i++;
  832. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 */
  833. i++;
  834. msleep(20);
  835. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */
  836. i++;
  837. /*jfm:win i2c_r from 00 to 80*/
  838. while (ov7630_sensor_init[i][0]) {
  839. i2c_w8(gspca_dev, ov7630_sensor_init[i]);
  840. i++;
  841. }
  842. }
  843. static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
  844. {
  845. int i = 0;
  846. while (ov7648_sensor_init[i][0]) {
  847. i2c_w8(gspca_dev, ov7648_sensor_init[i]);
  848. i++;
  849. }
  850. }
  851. static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
  852. {
  853. int i = 0;
  854. i2c_w8(gspca_dev, ov7660_sensor_init[i]); /* reset SCCB */
  855. i++;
  856. msleep(20);
  857. while (ov7660_sensor_init[i][0]) {
  858. i2c_w8(gspca_dev, ov7660_sensor_init[i]);
  859. i++;
  860. }
  861. }
  862. /* this function is called at probe time */
  863. static int sd_config(struct gspca_dev *gspca_dev,
  864. const struct usb_device_id *id)
  865. {
  866. struct sd *sd = (struct sd *) gspca_dev;
  867. struct cam *cam;
  868. cam = &gspca_dev->cam;
  869. cam->epaddr = 0x01;
  870. cam->cam_mode = vga_mode;
  871. cam->nmodes = ARRAY_SIZE(vga_mode);
  872. sd->bridge = id->driver_info >> 16;
  873. sd->sensor = id->driver_info >> 8;
  874. sd->i2c_base = id->driver_info;
  875. sd->qindex = 4; /* set the quantization table */
  876. sd->brightness = BRIGHTNESS_DEF;
  877. sd->contrast = CONTRAST_DEF;
  878. sd->colors = COLOR_DEF;
  879. sd->autogain = AUTOGAIN_DEF;
  880. sd->ag_cnt = -1;
  881. switch (sd->sensor) {
  882. case SENSOR_OV7630:
  883. case SENSOR_OV7648:
  884. case SENSOR_OV7660:
  885. gspca_dev->ctrl_dis = (1 << AUTOGAIN_IDX);
  886. break;
  887. }
  888. return 0;
  889. }
  890. /* this function is called at probe and resume time */
  891. static int sd_init(struct gspca_dev *gspca_dev)
  892. {
  893. struct sd *sd = (struct sd *) gspca_dev;
  894. /* const __u8 *sn9c1xx; */
  895. __u8 regGpio[] = { 0x29, 0x74 };
  896. __u8 regF1;
  897. /* setup a selector by bridge */
  898. reg_w1(gspca_dev, 0xf1, 0x01);
  899. reg_r(gspca_dev, 0x00, 1);
  900. reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
  901. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  902. regF1 = gspca_dev->usb_buf[0];
  903. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  904. switch (sd->bridge) {
  905. case BRIDGE_SN9C102P:
  906. if (regF1 != 0x11)
  907. return -ENODEV;
  908. reg_w1(gspca_dev, 0x02, regGpio[1]);
  909. break;
  910. case BRIDGE_SN9C105:
  911. if (regF1 != 0x11)
  912. return -ENODEV;
  913. reg_w(gspca_dev, 0x02, regGpio, 2);
  914. break;
  915. case BRIDGE_SN9C120:
  916. if (regF1 != 0x12)
  917. return -ENODEV;
  918. regGpio[1] = 0x70;
  919. reg_w(gspca_dev, 0x02, regGpio, 2);
  920. break;
  921. default:
  922. /* case BRIDGE_SN9C110: */
  923. /* case BRIDGE_SN9C325: */
  924. if (regF1 != 0x12)
  925. return -ENODEV;
  926. reg_w1(gspca_dev, 0x02, 0x62);
  927. break;
  928. }
  929. reg_w1(gspca_dev, 0xf1, 0x01);
  930. return 0;
  931. }
  932. static unsigned int setexposure(struct gspca_dev *gspca_dev,
  933. unsigned int expo)
  934. {
  935. struct sd *sd = (struct sd *) gspca_dev;
  936. static const __u8 doit[] = /* update sensor */
  937. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  938. static const __u8 sensorgo[] = /* sensor on */
  939. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  940. static const __u8 gainMo[] =
  941. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  942. switch (sd->sensor) {
  943. case SENSOR_HV7131R: {
  944. __u8 Expodoit[] =
  945. { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
  946. Expodoit[3] = expo >> 16;
  947. Expodoit[4] = expo >> 8;
  948. Expodoit[5] = expo;
  949. i2c_w8(gspca_dev, Expodoit);
  950. break;
  951. }
  952. case SENSOR_MI0360: {
  953. __u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  954. { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
  955. if (expo > 0x0635)
  956. expo = 0x0635;
  957. else if (expo < 0x0001)
  958. expo = 0x0001;
  959. expoMi[3] = expo >> 8;
  960. expoMi[4] = expo;
  961. i2c_w8(gspca_dev, expoMi);
  962. i2c_w8(gspca_dev, doit);
  963. i2c_w8(gspca_dev, sensorgo);
  964. break;
  965. }
  966. case SENSOR_MO4000: {
  967. __u8 expoMof[] =
  968. { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
  969. __u8 expoMo10[] =
  970. { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
  971. if (expo > 0x1fff)
  972. expo = 0x1fff;
  973. else if (expo < 0x0001)
  974. expo = 0x0001;
  975. expoMof[3] = (expo & 0x03fc) >> 2;
  976. i2c_w8(gspca_dev, expoMof);
  977. expoMo10[3] = ((expo & 0x1c00) >> 10)
  978. | ((expo & 0x0003) << 4);
  979. i2c_w8(gspca_dev, expoMo10);
  980. i2c_w8(gspca_dev, gainMo);
  981. PDEBUG(D_CONF, "set exposure %d",
  982. ((expoMo10[3] & 0x07) << 10)
  983. | (expoMof[3] << 2)
  984. | ((expoMo10[3] & 0x30) >> 4));
  985. break;
  986. }
  987. case SENSOR_OM6802: {
  988. __u8 gainOm[] =
  989. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  990. if (expo > 0x03ff)
  991. expo = 0x03ff;
  992. if (expo < 0x0001)
  993. expo = 0x0001;
  994. gainOm[3] = expo >> 2;
  995. i2c_w8(gspca_dev, gainOm);
  996. reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f);
  997. PDEBUG(D_CONF, "set exposure %d", gainOm[3]);
  998. break;
  999. }
  1000. }
  1001. return expo;
  1002. }
  1003. /* this function is used for sensors o76xx only */
  1004. static void setbrightcont(struct gspca_dev *gspca_dev)
  1005. {
  1006. struct sd *sd = (struct sd *) gspca_dev;
  1007. unsigned val;
  1008. __u8 reg84_full[0x15];
  1009. memset(reg84_full, 0, sizeof reg84_full);
  1010. val = sd->contrast * 0x20 / CONTRAST_MAX + 0x10; /* 10..30 */
  1011. reg84_full[2] = val;
  1012. reg84_full[0] = (val + 1) / 2;
  1013. reg84_full[4] = (val + 1) / 5;
  1014. if (val > BRIGHTNESS_DEF)
  1015. val = (sd->brightness - BRIGHTNESS_DEF) * 0x20
  1016. / BRIGHTNESS_MAX;
  1017. else
  1018. val = 0;
  1019. reg84_full[0x12] = val; /* 00..1f */
  1020. reg_w(gspca_dev, 0x84, reg84_full, sizeof reg84_full);
  1021. }
  1022. /* sensor != ov76xx */
  1023. static void setbrightness(struct gspca_dev *gspca_dev)
  1024. {
  1025. struct sd *sd = (struct sd *) gspca_dev;
  1026. unsigned int expo;
  1027. __u8 k2;
  1028. k2 = sd->brightness >> 10;
  1029. switch (sd->sensor) {
  1030. case SENSOR_HV7131R:
  1031. expo = sd->brightness << 4;
  1032. if (expo > 0x002dc6c0)
  1033. expo = 0x002dc6c0;
  1034. else if (expo < 0x02a0)
  1035. expo = 0x02a0;
  1036. sd->exposure = setexposure(gspca_dev, expo);
  1037. break;
  1038. case SENSOR_MI0360:
  1039. case SENSOR_MO4000:
  1040. expo = sd->brightness >> 4;
  1041. sd->exposure = setexposure(gspca_dev, expo);
  1042. break;
  1043. case SENSOR_OM6802:
  1044. expo = sd->brightness >> 6;
  1045. sd->exposure = setexposure(gspca_dev, expo);
  1046. k2 = sd->brightness >> 11;
  1047. break;
  1048. }
  1049. reg_w1(gspca_dev, 0x96, k2);
  1050. }
  1051. /* sensor != ov76xx */
  1052. static void setcontrast(struct gspca_dev *gspca_dev)
  1053. {
  1054. struct sd *sd = (struct sd *) gspca_dev;
  1055. __u8 k2;
  1056. __u8 contrast[] = { 0x00, 0x00, 0x28, 0x00, 0x07, 0x00 };
  1057. k2 = sd->contrast;
  1058. contrast[2] = k2;
  1059. contrast[0] = (k2 + 1) >> 1;
  1060. contrast[4] = (k2 + 1) / 5;
  1061. reg_w(gspca_dev, 0x84, contrast, 6);
  1062. }
  1063. static void setcolors(struct gspca_dev *gspca_dev)
  1064. {
  1065. struct sd *sd = (struct sd *) gspca_dev;
  1066. __u8 blue, red;
  1067. if (sd->colors >= 32) {
  1068. red = 32 + (sd->colors - 32) / 2;
  1069. blue = 64 - sd->colors;
  1070. } else {
  1071. red = sd->colors;
  1072. blue = 32 + (32 - sd->colors) / 2;
  1073. }
  1074. reg_w1(gspca_dev, 0x05, red);
  1075. /* reg_w1(gspca_dev, 0x07, 32); */
  1076. reg_w1(gspca_dev, 0x06, blue);
  1077. }
  1078. static void setautogain(struct gspca_dev *gspca_dev)
  1079. {
  1080. struct sd *sd = (struct sd *) gspca_dev;
  1081. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
  1082. return;
  1083. if (sd->autogain)
  1084. sd->ag_cnt = AG_CNT_START;
  1085. else
  1086. sd->ag_cnt = -1;
  1087. }
  1088. /* -- start the camera -- */
  1089. static void sd_start(struct gspca_dev *gspca_dev)
  1090. {
  1091. struct sd *sd = (struct sd *) gspca_dev;
  1092. int i;
  1093. __u8 reg1, reg17, reg18;
  1094. const __u8 *sn9c1xx;
  1095. int mode;
  1096. static const __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  1097. static const __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  1098. static const __u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  1099. static const __u8 CE_ov76xx[] =
  1100. { 0x32, 0xdd, 0x32, 0xdd }; /* OV7630/48 */
  1101. sn9c1xx = sn_tb[(int) sd->sensor];
  1102. configure_gpio(gspca_dev, sn9c1xx);
  1103. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  1104. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  1105. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  1106. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  1107. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  1108. reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
  1109. reg_w1(gspca_dev, 0xd3, 0x50);
  1110. reg_w1(gspca_dev, 0xc6, 0x00);
  1111. reg_w1(gspca_dev, 0xc7, 0x00);
  1112. reg_w1(gspca_dev, 0xc8, 0x50);
  1113. reg_w1(gspca_dev, 0xc9, 0x3c);
  1114. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  1115. switch (sd->sensor) {
  1116. case SENSOR_OV7630:
  1117. reg17 = 0xe2;
  1118. break;
  1119. case SENSOR_OV7648:
  1120. reg17 = 0xae;
  1121. break;
  1122. /*jfm: from win trace */
  1123. case SENSOR_OV7660:
  1124. reg17 = 0xa0;
  1125. break;
  1126. default:
  1127. reg17 = 0x60;
  1128. break;
  1129. }
  1130. reg_w1(gspca_dev, 0x17, reg17);
  1131. reg_w1(gspca_dev, 0x05, sn9c1xx[5]);
  1132. reg_w1(gspca_dev, 0x07, sn9c1xx[7]);
  1133. reg_w1(gspca_dev, 0x06, sn9c1xx[6]);
  1134. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  1135. reg_w(gspca_dev, 0x20, gamma_def, sizeof gamma_def);
  1136. for (i = 0; i < 8; i++)
  1137. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  1138. reg_w1(gspca_dev, 0x9a, 0x08);
  1139. reg_w1(gspca_dev, 0x99, 0x59);
  1140. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  1141. if (mode)
  1142. reg1 = 0x46; /* 320 clk 48Mhz */
  1143. else
  1144. reg1 = 0x06; /* 640 clk 24Mz */
  1145. reg17 = 0x61;
  1146. switch (sd->sensor) {
  1147. case SENSOR_HV7131R:
  1148. hv7131R_InitSensor(gspca_dev);
  1149. break;
  1150. case SENSOR_MI0360:
  1151. mi0360_InitSensor(gspca_dev);
  1152. break;
  1153. case SENSOR_MO4000:
  1154. mo4000_InitSensor(gspca_dev);
  1155. if (mode) {
  1156. /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
  1157. reg1 = 0x06; /* clk 24Mz */
  1158. } else {
  1159. reg17 = 0x22; /* 640 MCKSIZE */
  1160. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  1161. }
  1162. break;
  1163. case SENSOR_OM6802:
  1164. om6802_InitSensor(gspca_dev);
  1165. reg17 = 0x64; /* 640 MCKSIZE */
  1166. break;
  1167. case SENSOR_OV7630:
  1168. ov7630_InitSensor(gspca_dev);
  1169. reg17 = 0xe2;
  1170. reg1 = 0x44;
  1171. break;
  1172. case SENSOR_OV7648:
  1173. ov7648_InitSensor(gspca_dev);
  1174. reg17 = 0xa2;
  1175. reg1 = 0x44;
  1176. /* if (mode)
  1177. ; * 320x2...
  1178. else
  1179. ; * 640x... */
  1180. break;
  1181. default:
  1182. /* case SENSOR_OV7660: */
  1183. ov7660_InitSensor(gspca_dev);
  1184. if (mode) {
  1185. /* reg17 = 0x21; * 320 */
  1186. /* reg1 = 0x44; */
  1187. /* reg1 = 0x46; (done) */
  1188. } else {
  1189. reg17 = 0x22; /* 640 MCKSIZE */
  1190. reg1 = 0x06;
  1191. }
  1192. break;
  1193. }
  1194. reg_w(gspca_dev, 0xc0, C0, 6);
  1195. reg_w(gspca_dev, 0xca, CA, 4);
  1196. switch (sd->sensor) {
  1197. case SENSOR_OV7630:
  1198. case SENSOR_OV7648:
  1199. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  1200. break;
  1201. default:
  1202. reg_w(gspca_dev, 0xce, CE, 4);
  1203. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  1204. break;
  1205. }
  1206. /* here change size mode 0 -> VGA; 1 -> CIF */
  1207. reg18 = sn9c1xx[0x18] | (mode << 4);
  1208. reg_w1(gspca_dev, 0x18, reg18 | 0x40);
  1209. reg_w(gspca_dev, 0x100, qtable4, 0x40);
  1210. reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40);
  1211. reg_w1(gspca_dev, 0x18, reg18);
  1212. reg_w1(gspca_dev, 0x17, reg17);
  1213. switch (sd->sensor) {
  1214. case SENSOR_HV7131R:
  1215. case SENSOR_MI0360:
  1216. case SENSOR_MO4000:
  1217. case SENSOR_OM6802:
  1218. setbrightness(gspca_dev);
  1219. setcontrast(gspca_dev);
  1220. break;
  1221. default: /* OV76xx */
  1222. setbrightcont(gspca_dev);
  1223. break;
  1224. }
  1225. setautogain(gspca_dev);
  1226. reg_w1(gspca_dev, 0x01, reg1);
  1227. }
  1228. static void sd_stopN(struct gspca_dev *gspca_dev)
  1229. {
  1230. struct sd *sd = (struct sd *) gspca_dev;
  1231. static const __u8 stophv7131[] =
  1232. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  1233. static const __u8 stopmi0360[] =
  1234. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1235. __u8 data;
  1236. const __u8 *sn9c1xx;
  1237. data = 0x0b;
  1238. switch (sd->sensor) {
  1239. case SENSOR_HV7131R:
  1240. i2c_w8(gspca_dev, stophv7131);
  1241. data = 0x2b;
  1242. break;
  1243. case SENSOR_MI0360:
  1244. i2c_w8(gspca_dev, stopmi0360);
  1245. data = 0x29;
  1246. break;
  1247. case SENSOR_OV7630:
  1248. case SENSOR_OV7648:
  1249. data = 0x29;
  1250. break;
  1251. default:
  1252. /* case SENSOR_MO4000: */
  1253. /* case SENSOR_OV7660: */
  1254. break;
  1255. }
  1256. sn9c1xx = sn_tb[(int) sd->sensor];
  1257. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1258. reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
  1259. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1260. reg_w1(gspca_dev, 0x01, data);
  1261. reg_w1(gspca_dev, 0xf1, 0x00);
  1262. }
  1263. static void do_autogain(struct gspca_dev *gspca_dev)
  1264. {
  1265. struct sd *sd = (struct sd *) gspca_dev;
  1266. int delta;
  1267. int expotimes;
  1268. __u8 luma_mean = 130;
  1269. __u8 luma_delta = 20;
  1270. /* Thanks S., without your advice, autobright should not work :) */
  1271. if (sd->ag_cnt < 0)
  1272. return;
  1273. if (--sd->ag_cnt >= 0)
  1274. return;
  1275. sd->ag_cnt = AG_CNT_START;
  1276. delta = atomic_read(&sd->avg_lum);
  1277. PDEBUG(D_FRAM, "mean lum %d", delta);
  1278. if (delta < luma_mean - luma_delta ||
  1279. delta > luma_mean + luma_delta) {
  1280. switch (sd->sensor) {
  1281. case SENSOR_HV7131R:
  1282. expotimes = sd->exposure >> 8;
  1283. expotimes += (luma_mean - delta) >> 4;
  1284. if (expotimes < 0)
  1285. expotimes = 0;
  1286. sd->exposure = setexposure(gspca_dev,
  1287. (unsigned int) (expotimes << 8));
  1288. break;
  1289. default:
  1290. /* case SENSOR_MO4000: */
  1291. /* case SENSOR_MI0360: */
  1292. /* case SENSOR_OM6802: */
  1293. expotimes = sd->exposure;
  1294. expotimes += (luma_mean - delta) >> 6;
  1295. if (expotimes < 0)
  1296. expotimes = 0;
  1297. sd->exposure = setexposure(gspca_dev,
  1298. (unsigned int) expotimes);
  1299. setcolors(gspca_dev);
  1300. break;
  1301. }
  1302. }
  1303. }
  1304. /* scan the URB packets */
  1305. /* This function is run at interrupt level. */
  1306. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1307. struct gspca_frame *frame, /* target */
  1308. __u8 *data, /* isoc packet */
  1309. int len) /* iso packet length */
  1310. {
  1311. struct sd *sd = (struct sd *) gspca_dev;
  1312. int sof, avg_lum;
  1313. sof = len - 64;
  1314. if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
  1315. /* end of frame */
  1316. gspca_frame_add(gspca_dev, LAST_PACKET,
  1317. frame, data, sof + 2);
  1318. if (sd->ag_cnt < 0)
  1319. return;
  1320. /* w1 w2 w3 */
  1321. /* w4 w5 w6 */
  1322. /* w7 w8 */
  1323. /* w4 */
  1324. avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
  1325. /* w6 */
  1326. avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
  1327. /* w2 */
  1328. avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
  1329. /* w8 */
  1330. avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
  1331. /* w5 */
  1332. avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
  1333. avg_lum >>= 4;
  1334. atomic_set(&sd->avg_lum, avg_lum);
  1335. return;
  1336. }
  1337. if (gspca_dev->last_packet_type == LAST_PACKET) {
  1338. /* put the JPEG 422 header */
  1339. jpeg_put_header(gspca_dev, frame, sd->qindex, 0x21);
  1340. }
  1341. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  1342. }
  1343. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1344. {
  1345. struct sd *sd = (struct sd *) gspca_dev;
  1346. sd->brightness = val;
  1347. if (gspca_dev->streaming) {
  1348. switch (sd->sensor) {
  1349. case SENSOR_HV7131R:
  1350. case SENSOR_MI0360:
  1351. case SENSOR_MO4000:
  1352. case SENSOR_OM6802:
  1353. setbrightness(gspca_dev);
  1354. break;
  1355. default: /* OV76xx */
  1356. setbrightcont(gspca_dev);
  1357. break;
  1358. }
  1359. }
  1360. return 0;
  1361. }
  1362. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1363. {
  1364. struct sd *sd = (struct sd *) gspca_dev;
  1365. *val = sd->brightness;
  1366. return 0;
  1367. }
  1368. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1369. {
  1370. struct sd *sd = (struct sd *) gspca_dev;
  1371. sd->contrast = val;
  1372. if (gspca_dev->streaming) {
  1373. switch (sd->sensor) {
  1374. case SENSOR_HV7131R:
  1375. case SENSOR_MI0360:
  1376. case SENSOR_MO4000:
  1377. case SENSOR_OM6802:
  1378. setcontrast(gspca_dev);
  1379. break;
  1380. default: /* OV76xx */
  1381. setbrightcont(gspca_dev);
  1382. break;
  1383. }
  1384. }
  1385. return 0;
  1386. }
  1387. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1388. {
  1389. struct sd *sd = (struct sd *) gspca_dev;
  1390. *val = sd->contrast;
  1391. return 0;
  1392. }
  1393. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1394. {
  1395. struct sd *sd = (struct sd *) gspca_dev;
  1396. sd->colors = val;
  1397. if (gspca_dev->streaming)
  1398. setcolors(gspca_dev);
  1399. return 0;
  1400. }
  1401. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1402. {
  1403. struct sd *sd = (struct sd *) gspca_dev;
  1404. *val = sd->colors;
  1405. return 0;
  1406. }
  1407. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1408. {
  1409. struct sd *sd = (struct sd *) gspca_dev;
  1410. sd->autogain = val;
  1411. if (gspca_dev->streaming)
  1412. setautogain(gspca_dev);
  1413. return 0;
  1414. }
  1415. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1416. {
  1417. struct sd *sd = (struct sd *) gspca_dev;
  1418. *val = sd->autogain;
  1419. return 0;
  1420. }
  1421. /* sub-driver description */
  1422. static const struct sd_desc sd_desc = {
  1423. .name = MODULE_NAME,
  1424. .ctrls = sd_ctrls,
  1425. .nctrls = ARRAY_SIZE(sd_ctrls),
  1426. .config = sd_config,
  1427. .init = sd_init,
  1428. .start = sd_start,
  1429. .stopN = sd_stopN,
  1430. .pkt_scan = sd_pkt_scan,
  1431. .dq_callback = do_autogain,
  1432. };
  1433. /* -- module initialisation -- */
  1434. #define BSI(bridge, sensor, i2c_addr) \
  1435. .driver_info = (BRIDGE_ ## bridge << 16) \
  1436. | (SENSOR_ ## sensor << 8) \
  1437. | (i2c_addr)
  1438. static const __devinitdata struct usb_device_id device_table[] = {
  1439. #ifndef CONFIG_USB_SN9C102
  1440. {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
  1441. {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
  1442. {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
  1443. {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
  1444. {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
  1445. #endif
  1446. {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
  1447. {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},
  1448. /* bw600.inf:
  1449. {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, MI0360, 0x5d)}, */
  1450. /* {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x??)}, */
  1451. /* {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x??)}, */
  1452. {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
  1453. /* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */
  1454. {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
  1455. /* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, */
  1456. /* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
  1457. {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
  1458. /* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
  1459. /* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
  1460. {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
  1461. {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
  1462. /* {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x??)}, */
  1463. /* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
  1464. /* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
  1465. /* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
  1466. {USB_DEVICE(0x0c45, 0x6128), BSI(SN9C110, OM6802, 0x21)}, /*sn9c325?*/
  1467. /*bw600.inf:*/
  1468. {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C110, OV7648, 0x21)}, /*sn9c325?*/
  1469. {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)},
  1470. {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x21)},
  1471. /* {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */
  1472. #ifndef CONFIG_USB_SN9C102
  1473. {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
  1474. {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
  1475. /* {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x??)}, */
  1476. {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
  1477. {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
  1478. /* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */
  1479. #endif
  1480. {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, MI0360, 0x5d)},
  1481. {}
  1482. };
  1483. MODULE_DEVICE_TABLE(usb, device_table);
  1484. /* -- device connect -- */
  1485. static int sd_probe(struct usb_interface *intf,
  1486. const struct usb_device_id *id)
  1487. {
  1488. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1489. THIS_MODULE);
  1490. }
  1491. static struct usb_driver sd_driver = {
  1492. .name = MODULE_NAME,
  1493. .id_table = device_table,
  1494. .probe = sd_probe,
  1495. .disconnect = gspca_disconnect,
  1496. #ifdef CONFIG_PM
  1497. .suspend = gspca_suspend,
  1498. .resume = gspca_resume,
  1499. #endif
  1500. };
  1501. /* -- module insert / remove -- */
  1502. static int __init sd_mod_init(void)
  1503. {
  1504. if (usb_register(&sd_driver) < 0)
  1505. return -1;
  1506. info("registered");
  1507. return 0;
  1508. }
  1509. static void __exit sd_mod_exit(void)
  1510. {
  1511. usb_deregister(&sd_driver);
  1512. info("deregistered");
  1513. }
  1514. module_init(sd_mod_init);
  1515. module_exit(sd_mod_exit);