sonixj.c 43 KB

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