sonixj.c 46 KB

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