sonixj.c 47 KB

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