sonixj.c 46 KB

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