sonixj.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  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, 3)
  25. static const char version[] = "2.1.3";
  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. const __u8 *buffer,
  488. int len)
  489. {
  490. __u8 tmpbuf[64];
  491. #ifdef CONFIG_VIDEO_ADV_DEBUG
  492. if (len > sizeof tmpbuf) {
  493. PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow");
  494. return;
  495. }
  496. #endif
  497. memcpy(tmpbuf, buffer, len);
  498. usb_control_msg(dev,
  499. usb_sndctrlpipe(dev, 0),
  500. 0x08,
  501. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  502. value, 0,
  503. tmpbuf, len,
  504. 500);
  505. }
  506. /* write 2 bytes */
  507. static void i2c_w2(struct gspca_dev *gspca_dev,
  508. __u8 *buffer)
  509. {
  510. struct sd *sd = (struct sd *) gspca_dev;
  511. struct usb_device *dev = gspca_dev->dev;
  512. __u8 mode[8];
  513. /* is i2c ready */
  514. mode[0] = sd->i2c_ctrl_reg | (2 << 4);
  515. mode[1] = sd->i2c_base;
  516. mode[2] = buffer[0];
  517. mode[3] = buffer[1];
  518. mode[4] = 0;
  519. mode[5] = 0;
  520. mode[6] = 0;
  521. mode[7] = 0x10;
  522. reg_w(dev, 0x08, mode, 8);
  523. }
  524. /* write 8 bytes */
  525. static void i2c_w8(struct usb_device *dev, __u8 *buffer)
  526. {
  527. reg_w(dev, 0x08, buffer, 8);
  528. msleep(1);
  529. }
  530. /* read 5 bytes */
  531. static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg,
  532. __u8 *buffer)
  533. {
  534. struct sd *sd = (struct sd *) gspca_dev;
  535. struct usb_device *dev = gspca_dev->dev;
  536. __u8 mode[8];
  537. mode[0] = sd->i2c_ctrl_reg | 0x10;
  538. mode[1] = sd->i2c_base;
  539. mode[2] = reg;
  540. mode[3] = 0;
  541. mode[4] = 0;
  542. mode[5] = 0;
  543. mode[6] = 0;
  544. mode[7] = 0x10;
  545. i2c_w8(dev, mode);
  546. mode[0] = sd->i2c_ctrl_reg | (5 << 4) | 0x02;
  547. mode[2] = 0;
  548. i2c_w8(dev, mode);
  549. reg_r(dev, 0x0a, buffer, 5);
  550. }
  551. static int probesensor(struct gspca_dev *gspca_dev)
  552. {
  553. struct sd *sd = (struct sd *) gspca_dev;
  554. struct usb_device *dev = gspca_dev->dev;
  555. __u8 reg02;
  556. static __u8 datasend[] = { 2, 0 };
  557. /* reg val1 val2 val3 val4 */
  558. __u8 datarecd[6];
  559. i2c_w2(gspca_dev, datasend);
  560. /* should write 0xa1 0x11 0x02 0x00 0x00 0x00 0x00 the 0x10 is add by i2cw */
  561. msleep(10);
  562. reg02 = 0x66;
  563. reg_w(dev, 0x02, &reg02, 1); /* Gpio on */
  564. msleep(10);
  565. i2c_r5(gspca_dev, 0, datarecd); /* read sensor id */
  566. if (datarecd[0] == 0x02
  567. && datarecd[1] == 0x09
  568. && datarecd[2] == 0x01
  569. && datarecd[3] == 0x00
  570. && datarecd[4] == 0x00) {
  571. PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
  572. sd->sensor = SENSOR_HV7131R;
  573. return SENSOR_HV7131R;
  574. }
  575. PDEBUG(D_PROBE, "Find Sensor %d %d %d",
  576. datarecd[0], datarecd[1], datarecd[2]);
  577. PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
  578. return -ENODEV;
  579. }
  580. static int configure_gpio(struct gspca_dev *gspca_dev,
  581. __u8 *sn9c1xx)
  582. {
  583. struct sd *sd = (struct sd *) gspca_dev;
  584. struct usb_device *dev = gspca_dev->dev;
  585. __u8 data;
  586. __u8 regF1;
  587. __u8 *reg9a;
  588. static __u8 reg9a_def[] =
  589. {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
  590. static __u8 reg9a_sn9c120[] = /* from win trace */
  591. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  592. static __u8 reg9a_sn9c325[] =
  593. {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
  594. regF1 = 0x00;
  595. reg_w(dev, 0xf1, &regF1, 1);
  596. reg_w(dev, 0x01, &sn9c1xx[0], 1); /*fixme:jfm was [1] en v1*/
  597. /* configure gpio */
  598. reg_w(dev, 0x01, &sn9c1xx[1], 2);
  599. reg_w(dev, 0x08, &sn9c1xx[8], 2);
  600. reg_w(dev, 0x17, &sn9c1xx[0x17], 3);
  601. switch (sd->customid) {
  602. case SN9C325:
  603. reg9a = reg9a_sn9c325;
  604. break;
  605. case SN9C120:
  606. reg9a = reg9a_sn9c120;
  607. break;
  608. default:
  609. reg9a = reg9a_def;
  610. break;
  611. }
  612. reg_w(dev, 0x9a, reg9a, 6);
  613. data = 0x60; /*fixme:jfm 60 00 00 (3) */
  614. reg_w(dev, 0xd4, &data, 1);
  615. reg_w(dev, 0x03, &sn9c1xx[3], 0x0f);
  616. switch (sd->customid) {
  617. case SN9C120: /* from win trace */
  618. data = 0x61;
  619. reg_w(dev, 0x01, &data, 1);
  620. data = 0x20;
  621. reg_w(dev, 0x17, &data, 1);
  622. data = 0x60;
  623. reg_w(dev, 0x01, &data, 1);
  624. break;
  625. case SN9C325:
  626. data = 0x43;
  627. reg_w(dev, 0x01, &data, 1);
  628. data = 0xae;
  629. reg_w(dev, 0x17, &data, 1);
  630. data = 0x42;
  631. reg_w(dev, 0x01, &data, 1);
  632. break;
  633. default:
  634. data = 0x43;
  635. reg_w(dev, 0x01, &data, 1);
  636. data = 0x61;
  637. reg_w(dev, 0x17, &data, 1);
  638. data = 0x42;
  639. reg_w(dev, 0x01, &data, 1);
  640. }
  641. if (sd->sensor == SENSOR_HV7131R) {
  642. if (probesensor(gspca_dev) < 0)
  643. return -ENODEV;
  644. }
  645. return 0;
  646. }
  647. static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
  648. {
  649. int i = 0;
  650. struct usb_device *dev = gspca_dev->dev;
  651. static __u8 SetSensorClk[] = /* 0x08 Mclk */
  652. { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
  653. while (hv7131r_sensor_init[i][0]) {
  654. i2c_w8(dev, hv7131r_sensor_init[i]);
  655. i++;
  656. }
  657. i2c_w8(dev, SetSensorClk);
  658. }
  659. static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
  660. {
  661. int i = 0;
  662. struct usb_device *dev = gspca_dev->dev;
  663. while (mi0360_sensor_init[i][0]) {
  664. i2c_w8(dev, mi0360_sensor_init[i]);
  665. i++;
  666. }
  667. }
  668. static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
  669. {
  670. int i = 0;
  671. struct usb_device *dev = gspca_dev->dev;
  672. while (mo4000_sensor_init[i][0]) {
  673. i2c_w8(dev, mo4000_sensor_init[i]);
  674. i++;
  675. }
  676. }
  677. static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
  678. {
  679. struct usb_device *dev = gspca_dev->dev;
  680. int i = 0;
  681. while (ov7648_sensor_init[i][0]) {
  682. i2c_w8(dev, ov7648_sensor_init[i]);
  683. i++;
  684. }
  685. }
  686. static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
  687. {
  688. int i = 0;
  689. struct usb_device *dev = gspca_dev->dev;
  690. while (ov7660_sensor_init[i][0]) {
  691. i2c_w8(dev, ov7660_sensor_init[i]);
  692. i++;
  693. }
  694. }
  695. /* this function is called at probe time */
  696. static int sd_config(struct gspca_dev *gspca_dev,
  697. const struct usb_device_id *id)
  698. {
  699. struct sd *sd = (struct sd *) gspca_dev;
  700. struct cam *cam;
  701. __u16 vendor;
  702. __u16 product;
  703. vendor = id->idVendor;
  704. product = id->idProduct;
  705. sd->sensor = -1;
  706. switch (vendor) {
  707. case 0x0458: /* Genius */
  708. /* switch (product) {
  709. case 0x7025: */
  710. sd->customid = SN9C120;
  711. sd->sensor = SENSOR_MI0360;
  712. sd->i2c_ctrl_reg = 0x81;
  713. sd->i2c_base = 0x5d;
  714. /* break;
  715. } */
  716. break;
  717. case 0x045e:
  718. /* switch (product) {
  719. case 0x00f5:
  720. case 0x00f7: */
  721. sd->customid = SN9C105;
  722. sd->sensor = SENSOR_OV7660;
  723. sd->i2c_ctrl_reg = 0x81;
  724. sd->i2c_base = 0x21;
  725. /* break;
  726. } */
  727. break;
  728. case 0x0471: /* Philips */
  729. /* switch (product) {
  730. case 0x0327:
  731. case 0x0328:
  732. case 0x0330: */
  733. sd->customid = SN9C105;
  734. sd->sensor = SENSOR_MI0360;
  735. sd->i2c_ctrl_reg = 0x81;
  736. sd->i2c_base = 0x5d;
  737. /* break;
  738. } */
  739. break;
  740. case 0x0c45: /* Sonix */
  741. switch (product) {
  742. case 0x6040:
  743. sd->customid = SN9C102P;
  744. sd->sensor = SENSOR_MI0360; /* from BW600.inf */
  745. /* sd->sensor = SENSOR_HV7131R; * gspcav1 value */
  746. sd->i2c_ctrl_reg = 0x81;
  747. sd->i2c_base = 0x11;
  748. break;
  749. /* case 0x607a: * from BW600.inf
  750. sd->customid = SN9C102P;
  751. sd->sensor = SENSOR_OV7648;
  752. sd->i2c_ctrl_reg = 0x??;
  753. sd->i2c_base = 0x??;
  754. break; */
  755. case 0x607c:
  756. sd->customid = SN9C102P;
  757. sd->sensor = SENSOR_HV7131R;
  758. sd->i2c_ctrl_reg = 0x81;
  759. sd->i2c_base = 0x11;
  760. break;
  761. /* case 0x607e: * from BW600.inf
  762. sd->customid = SN9C102P;
  763. sd->sensor = SENSOR_OV7630;
  764. sd->i2c_ctrl_reg = 0x??;
  765. sd->i2c_base = 0x??;
  766. break; */
  767. case 0x60c0:
  768. sd->customid = SN9C105;
  769. sd->sensor = SENSOR_MI0360;
  770. sd->i2c_ctrl_reg = 0x81;
  771. sd->i2c_base = 0x5d;
  772. break;
  773. /* case 0x60c8: * from BW600.inf
  774. sd->customid = SN9C105;
  775. sd->sensor = SENSOR_OM6801;
  776. sd->i2c_ctrl_reg = 0x??;
  777. sd->i2c_base = 0x??;
  778. break; */
  779. /* case 0x60cc: * from BW600.inf
  780. sd->customid = SN9C105;
  781. sd->sensor = SENSOR_HV7131GP;
  782. sd->i2c_ctrl_reg = 0x??;
  783. sd->i2c_base = 0x??;
  784. break; */
  785. case 0x60ec:
  786. sd->customid = SN9C105;
  787. sd->sensor = SENSOR_MO4000;
  788. sd->i2c_ctrl_reg = 0x81;
  789. sd->i2c_base = 0x21;
  790. break;
  791. /* case 0x60ef: * from BW600.inf
  792. sd->customid = SN9C105;
  793. sd->sensor = SENSOR_ICM105C;
  794. sd->i2c_ctrl_reg = 0x??;
  795. sd->i2c_base = 0x??;
  796. break; */
  797. /* case 0x60fa: * from BW600.inf
  798. sd->customid = SN9C105;
  799. sd->sensor = SENSOR_OV7648;
  800. sd->i2c_ctrl_reg = 0x??;
  801. sd->i2c_base = 0x??;
  802. break; */
  803. case 0x60fb:
  804. sd->customid = SN9C105;
  805. sd->sensor = SENSOR_OV7660;
  806. sd->i2c_ctrl_reg = 0x81;
  807. sd->i2c_base = 0x21;
  808. break;
  809. case 0x60fc:
  810. sd->customid = SN9C105;
  811. sd->sensor = SENSOR_HV7131R;
  812. sd->i2c_ctrl_reg = 0x81;
  813. sd->i2c_base = 0x11;
  814. break;
  815. /* case 0x60fe: * from BW600.inf
  816. sd->customid = SN9C105;
  817. sd->sensor = SENSOR_OV7630;
  818. sd->i2c_ctrl_reg = 0x??;
  819. sd->i2c_base = 0x??;
  820. break; */
  821. /* case 0x6108: * from BW600.inf
  822. sd->customid = SN9C120;
  823. sd->sensor = SENSOR_OM6801;
  824. sd->i2c_ctrl_reg = 0x??;
  825. sd->i2c_base = 0x??;
  826. break; */
  827. /* case 0x6122: * from BW600.inf
  828. sd->customid = SN9C110;
  829. sd->sensor = SENSOR_ICM105C;
  830. sd->i2c_ctrl_reg = 0x??;
  831. sd->i2c_base = 0x??;
  832. break; */
  833. case 0x612a:
  834. /* sd->customid = SN9C110; * in BW600.inf */
  835. sd->customid = SN9C325;
  836. sd->sensor = SENSOR_OV7648;
  837. sd->i2c_ctrl_reg = 0x81;
  838. sd->i2c_base = 0x21;
  839. break;
  840. /* case 0x6123: * from BW600.inf
  841. sd->customid = SN9C110;
  842. sd->sensor = SENSOR_SanyoCCD;
  843. sd->i2c_ctrl_reg = 0x??;
  844. sd->i2c_base = 0x??;
  845. break; */
  846. case 0x612c:
  847. sd->customid = SN9C110;
  848. sd->sensor = SENSOR_MO4000;
  849. sd->i2c_ctrl_reg = 0x81;
  850. sd->i2c_base = 0x21;
  851. break;
  852. /* case 0x612e: * from BW600.inf
  853. sd->customid = SN9C110;
  854. sd->sensor = SENSOR_OV7630;
  855. sd->i2c_ctrl_reg = 0x??;
  856. sd->i2c_base = 0x??;
  857. break; */
  858. /* case 0x612f: * from BW600.inf
  859. sd->customid = SN9C110;
  860. sd->sensor = SENSOR_ICM105C;
  861. sd->i2c_ctrl_reg = 0x??;
  862. sd->i2c_base = 0x??;
  863. break; */
  864. case 0x6130:
  865. sd->customid = SN9C120;
  866. sd->sensor = SENSOR_MI0360;
  867. sd->i2c_ctrl_reg = 0x81;
  868. sd->i2c_base = 0x5d;
  869. break;
  870. case 0x6138:
  871. sd->customid = SN9C120;
  872. sd->sensor = SENSOR_MO4000;
  873. sd->i2c_ctrl_reg = 0x81;
  874. sd->i2c_base = 0x21;
  875. break;
  876. /* case 0x613a: * from BW600.inf
  877. sd->customid = SN9C120;
  878. sd->sensor = SENSOR_OV7648;
  879. sd->i2c_ctrl_reg = 0x??;
  880. sd->i2c_base = 0x??;
  881. break; */
  882. case 0x613b:
  883. sd->customid = SN9C120;
  884. sd->sensor = SENSOR_OV7660;
  885. sd->i2c_ctrl_reg = 0x81;
  886. sd->i2c_base = 0x21;
  887. break;
  888. case 0x613c:
  889. sd->customid = SN9C120;
  890. sd->sensor = SENSOR_HV7131R;
  891. sd->i2c_ctrl_reg = 0x81;
  892. sd->i2c_base = 0x11;
  893. break;
  894. /* case 0x613e: * from BW600.inf
  895. sd->customid = SN9C120;
  896. sd->sensor = SENSOR_OV7630;
  897. sd->i2c_ctrl_reg = 0x??;
  898. sd->i2c_base = 0x??;
  899. break; */
  900. }
  901. break;
  902. }
  903. if (sd->sensor < 0) {
  904. PDEBUG(D_ERR, "Invalid vendor/product %04x:%04x",
  905. vendor, product);
  906. return -EINVAL;
  907. }
  908. cam = &gspca_dev->cam;
  909. cam->dev_name = (char *) id->driver_info;
  910. cam->epaddr = 0x01;
  911. cam->cam_mode = vga_mode;
  912. cam->nmodes = ARRAY_SIZE(vga_mode);
  913. sd->qindex = 4; /* set the quantization table */
  914. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  915. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  916. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  917. sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value;
  918. return 0;
  919. }
  920. /* this function is called at open time */
  921. static int sd_open(struct gspca_dev *gspca_dev)
  922. {
  923. struct sd *sd = (struct sd *) gspca_dev;
  924. struct usb_device *dev = gspca_dev->dev;
  925. /* __u8 *sn9c1xx; */
  926. __u8 regF1;
  927. __u8 regGpio[] = { 0x29, 0x74 };
  928. /* setup a selector by customid */
  929. regF1 = 0x01;
  930. reg_w(dev, 0xf1, &regF1, 1);
  931. reg_r(dev, 0x00, &regF1, 1); /* -> regF1 = 0x00 */
  932. reg_w(dev, 0xf1, &regF1, 1);
  933. reg_r(dev, 0x00, &regF1, 1);
  934. switch (sd->customid) {
  935. case SN9C102P:
  936. if (regF1 != 0x11)
  937. return -ENODEV;
  938. reg_w(dev, 0x02, &regGpio[1], 1);
  939. break;
  940. case SN9C105:
  941. if (regF1 != 0x11)
  942. return -ENODEV;
  943. reg_w(dev, 0x02, regGpio, 2);
  944. break;
  945. case SN9C110:
  946. if (regF1 != 0x12)
  947. return -ENODEV;
  948. regGpio[1] = 0x62;
  949. reg_w(dev, 0x02, &regGpio[1], 1);
  950. break;
  951. case SN9C120:
  952. if (regF1 != 0x12)
  953. return -ENODEV;
  954. regGpio[1] = 0x70;
  955. reg_w(dev, 0x02, regGpio, 2);
  956. break;
  957. default:
  958. /* case SN9C325: */
  959. if (regF1 != 0x12)
  960. return -ENODEV;
  961. regGpio[1] = 0x62;
  962. reg_w(dev, 0x02, &regGpio[1], 1);
  963. break;
  964. }
  965. regF1 = 0x01;
  966. reg_w(dev, 0xf1, &regF1, 1);
  967. return 0;
  968. }
  969. static unsigned int setexposure(struct gspca_dev *gspca_dev,
  970. unsigned int expo)
  971. {
  972. struct sd *sd = (struct sd *) gspca_dev;
  973. static __u8 doit[] = /* update sensor */
  974. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  975. static __u8 sensorgo[] = /* sensor on */
  976. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  977. static __u8 gainMo[] =
  978. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  979. switch (sd->sensor) {
  980. case SENSOR_HV7131R: {
  981. __u8 Expodoit[] =
  982. { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
  983. Expodoit[3] = expo >> 16;
  984. Expodoit[4] = expo >> 8;
  985. Expodoit[5] = expo;
  986. i2c_w8(gspca_dev->dev, Expodoit);
  987. break;
  988. }
  989. case SENSOR_MI0360: {
  990. __u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  991. { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
  992. if (expo > 0x0635)
  993. expo = 0x0635;
  994. else if (expo < 0x0001)
  995. expo = 0x0001;
  996. expoMi[3] = expo >> 8;
  997. expoMi[4] = expo;
  998. i2c_w8(gspca_dev->dev, expoMi);
  999. i2c_w8(gspca_dev->dev, doit);
  1000. i2c_w8(gspca_dev->dev, sensorgo);
  1001. break;
  1002. }
  1003. case SENSOR_MO4000: {
  1004. __u8 expoMof[] =
  1005. { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
  1006. __u8 expoMo10[] =
  1007. { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
  1008. if (expo > 0x1fff)
  1009. expo = 0x1fff;
  1010. else if (expo < 0x0001)
  1011. expo = 0x0001;
  1012. expoMof[3] = (expo & 0x03fc) >> 2;
  1013. i2c_w8(gspca_dev->dev, expoMof);
  1014. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1015. | ((expo & 0x0003) << 4);
  1016. i2c_w8(gspca_dev->dev, expoMo10);
  1017. i2c_w8(gspca_dev->dev, gainMo);
  1018. PDEBUG(D_CONF, "set exposure %d",
  1019. ((expoMo10[3] & 0x07) << 10)
  1020. | (expoMof[3] << 2)
  1021. | ((expoMo10[3] & 0x30) >> 4));
  1022. break;
  1023. }
  1024. }
  1025. return expo;
  1026. }
  1027. static void setbrightness(struct gspca_dev *gspca_dev)
  1028. {
  1029. struct sd *sd = (struct sd *) gspca_dev;
  1030. unsigned int expo;
  1031. __u8 k2;
  1032. switch (sd->sensor) {
  1033. case SENSOR_HV7131R:
  1034. expo = sd->brightness << 4;
  1035. if (expo > 0x002dc6c0)
  1036. expo = 0x002dc6c0;
  1037. else if (expo < 0x02a0)
  1038. expo = 0x02a0;
  1039. sd->exposure = setexposure(gspca_dev, expo);
  1040. break;
  1041. case SENSOR_MI0360:
  1042. expo = sd->brightness >> 4;
  1043. sd->exposure = setexposure(gspca_dev, expo);
  1044. break;
  1045. case SENSOR_MO4000:
  1046. expo = sd->brightness >> 4;
  1047. sd->exposure = setexposure(gspca_dev, expo);
  1048. break;
  1049. case SENSOR_OV7660:
  1050. return; /*jfm??*/
  1051. }
  1052. k2 = sd->brightness >> 10;
  1053. reg_w(gspca_dev->dev, 0x96, &k2, 1);
  1054. }
  1055. static void setcontrast(struct gspca_dev *gspca_dev)
  1056. {
  1057. struct sd *sd = (struct sd *) gspca_dev;
  1058. __u8 k2;
  1059. __u8 contrast[] = { 0x00, 0x00, 0x28, 0x00, 0x07, 0x00 };
  1060. if (sd->sensor == SENSOR_OV7660)
  1061. return; /*jfm??*/
  1062. k2 = sd->contrast;
  1063. contrast[2] = k2;
  1064. contrast[0] = (k2 + 1) >> 1;
  1065. contrast[4] = (k2 + 1) / 5;
  1066. reg_w(gspca_dev->dev, 0x84, contrast, 6);
  1067. }
  1068. static void setcolors(struct gspca_dev *gspca_dev)
  1069. {
  1070. struct sd *sd = (struct sd *) gspca_dev;
  1071. __u8 data;
  1072. int colour;
  1073. colour = sd->colors - 128;
  1074. if (colour > 0)
  1075. data = (colour + 32) & 0x7f; /* blue */
  1076. else
  1077. data = (-colour + 32) & 0x7f; /* red */
  1078. reg_w(gspca_dev->dev, 0x05, &data, 1);
  1079. }
  1080. /* -- start the camera -- */
  1081. static void sd_start(struct gspca_dev *gspca_dev)
  1082. {
  1083. struct sd *sd = (struct sd *) gspca_dev;
  1084. struct usb_device *dev = gspca_dev->dev;
  1085. int i;
  1086. __u8 data;
  1087. __u8 reg1;
  1088. __u8 reg17;
  1089. __u8 *sn9c1xx;
  1090. int mode;
  1091. static __u8 DC29[] = { 0x6a, 0x50, 0x00, 0x00, 0x50, 0x3c };
  1092. static __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  1093. static __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  1094. static __u8 CA_sn9c120[] = { 0x14, 0xec, 0x0a, 0xf6 }; /* SN9C120 */
  1095. static __u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  1096. static __u8 CE_sn9c325[] =
  1097. { 0x32, 0xdd, 0x32, 0xdd }; /* OV7648 - SN9C325 */
  1098. sn9c1xx = sn_tb[(int) sd->sensor];
  1099. configure_gpio(gspca_dev, sn9c1xx);
  1100. /*fixme:jfm this sequence should appear at end of sd_start */
  1101. /* with
  1102. data = 0x44;
  1103. reg_w(dev, 0x01, &data, 1); */
  1104. reg_w(dev, 0x15, &sn9c1xx[0x15], 1);
  1105. reg_w(dev, 0x16, &sn9c1xx[0x16], 1);
  1106. reg_w(dev, 0x12, &sn9c1xx[0x12], 1);
  1107. reg_w(dev, 0x13, &sn9c1xx[0x13], 1);
  1108. reg_w(dev, 0x18, &sn9c1xx[0x18], 1);
  1109. reg_w(dev, 0xd2, &DC29[0], 1);
  1110. reg_w(dev, 0xd3, &DC29[1], 1);
  1111. reg_w(dev, 0xc6, &DC29[2], 1);
  1112. reg_w(dev, 0xc7, &DC29[3], 1);
  1113. reg_w(dev, 0xc8, &DC29[4], 1);
  1114. reg_w(dev, 0xc9, &DC29[5], 1);
  1115. /*fixme:jfm end of ending sequence */
  1116. reg_w(dev, 0x18, &sn9c1xx[0x18], 1);
  1117. if (sd->customid == SN9C325)
  1118. data = 0xae;
  1119. else
  1120. data = 0x60;
  1121. reg_w(dev, 0x17, &data, 1);
  1122. reg_w(dev, 0x05, &sn9c1xx[5], 1);
  1123. reg_w(dev, 0x07, &sn9c1xx[7], 1);
  1124. reg_w(dev, 0x06, &sn9c1xx[6], 1);
  1125. reg_w(dev, 0x14, &sn9c1xx[0x14], 1);
  1126. if (sd->customid == SN9C325) {
  1127. reg_w(dev, 0x20, regsn20_sn9c325, 0x11);
  1128. for (i = 0; i < 8; i++)
  1129. reg_w(dev, 0x84, reg84_sn9c325, 0x15);
  1130. data = 0x0a;
  1131. reg_w(dev, 0x9a, &data, 1);
  1132. data = 0x60;
  1133. reg_w(dev, 0x99, &data, 1);
  1134. } else {
  1135. reg_w(dev, 0x20, regsn20, 0x11);
  1136. for (i = 0; i < 8; i++)
  1137. reg_w(dev, 0x84, reg84, 0x15);
  1138. data = 0x08;
  1139. reg_w(dev, 0x9a, &data, 1);
  1140. data = 0x59;
  1141. reg_w(dev, 0x99, &data, 1);
  1142. }
  1143. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode;
  1144. reg1 = 0x02;
  1145. reg17 = 0x61;
  1146. switch (sd->sensor) {
  1147. case SENSOR_HV7131R:
  1148. hv7131R_InitSensor(gspca_dev);
  1149. if (mode)
  1150. reg1 = 0x46; /* 320 clk 48Mhz */
  1151. else
  1152. reg1 = 0x06; /* 640 clk 24Mz */
  1153. break;
  1154. case SENSOR_MI0360:
  1155. mi0360_InitSensor(gspca_dev);
  1156. if (mode)
  1157. reg1 = 0x46; /* 320 clk 48Mhz */
  1158. else
  1159. reg1 = 0x06; /* 640 clk 24Mz */
  1160. break;
  1161. case SENSOR_MO4000:
  1162. mo4000_InitSensor(gspca_dev);
  1163. if (mode) {
  1164. /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
  1165. reg1 = 0x06; /* clk 24Mz */
  1166. } else {
  1167. reg17 = 0x22; /* 640 MCKSIZE */
  1168. reg1 = 0x06; /* 640 clk 24Mz */
  1169. }
  1170. break;
  1171. case SENSOR_OV7648:
  1172. reg17 = 0xa2;
  1173. reg1 = 0x44;
  1174. ov7648_InitSensor(gspca_dev);
  1175. /* if (mode)
  1176. ; * 320x2...
  1177. else
  1178. ; * 640x... */
  1179. break;
  1180. default:
  1181. /* case SENSOR_OV7660: */
  1182. ov7660_InitSensor(gspca_dev);
  1183. if (mode) {
  1184. /* reg17 = 0x21; * 320 */
  1185. /* reg1 = 0x44; */
  1186. reg1 = 0x46;
  1187. } else {
  1188. reg17 = 0xa2; /* 640 */
  1189. reg1 = 0x40;
  1190. }
  1191. break;
  1192. }
  1193. reg_w(dev, 0xc0, C0, 6);
  1194. switch (sd->customid) {
  1195. case SN9C120: /*jfm ?? */
  1196. reg_w(dev, 0xca, CA_sn9c120, 4);
  1197. break;
  1198. default:
  1199. reg_w(dev, 0xca, CA, 4);
  1200. break;
  1201. }
  1202. switch (sd->customid) {
  1203. case SN9C120: /*jfm ?? */
  1204. case SN9C325:
  1205. reg_w(dev, 0xce, CE_sn9c325, 4);
  1206. break;
  1207. default:
  1208. reg_w(dev, 0xce, CE, 4);
  1209. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  1210. break;
  1211. }
  1212. /* here change size mode 0 -> VGA; 1 -> CIF */
  1213. data = 0x40 | sn9c1xx[0x18] | (mode << 4);
  1214. reg_w(dev, 0x18, &data, 1);
  1215. reg_w(dev, 0x100, qtable4, 0x40);
  1216. reg_w(dev, 0x140, qtable4 + 0x40, 0x40);
  1217. data = sn9c1xx[0x18] | (mode << 4);
  1218. reg_w(dev, 0x18, &data, 1);
  1219. reg_w(dev, 0x17, &reg17, 1);
  1220. reg_w(dev, 0x01, &reg1, 1);
  1221. setbrightness(gspca_dev);
  1222. setcontrast(gspca_dev);
  1223. }
  1224. static void sd_stopN(struct gspca_dev *gspca_dev)
  1225. {
  1226. struct sd *sd = (struct sd *) gspca_dev;
  1227. struct usb_device *dev = gspca_dev->dev;
  1228. static __u8 stophv7131[] =
  1229. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  1230. static __u8 stopmi0360[] =
  1231. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1232. __u8 regF1;
  1233. __u8 data;
  1234. __u8 *sn9c1xx;
  1235. data = 0x0b;
  1236. switch (sd->sensor) {
  1237. case SENSOR_HV7131R:
  1238. i2c_w8(dev, stophv7131);
  1239. data = 0x2b;
  1240. break;
  1241. case SENSOR_MI0360:
  1242. i2c_w8(dev, stopmi0360);
  1243. data = 0x29;
  1244. break;
  1245. case SENSOR_MO4000:
  1246. break;
  1247. case SENSOR_OV7648:
  1248. data = 0x29;
  1249. break;
  1250. default:
  1251. /* case SENSOR_OV7660: */
  1252. break;
  1253. }
  1254. sn9c1xx = sn_tb[(int) sd->sensor];
  1255. reg_w(dev, 0x01, &sn9c1xx[1], 1);
  1256. reg_w(dev, 0x17, &sn9c1xx[0x17], 1);
  1257. reg_w(dev, 0x01, &sn9c1xx[1], 1);
  1258. reg_w(dev, 0x01, &data, 1);
  1259. regF1 = 0x01;
  1260. reg_w(dev, 0xf1, &regF1, 1);
  1261. }
  1262. static void sd_stop0(struct gspca_dev *gspca_dev)
  1263. {
  1264. }
  1265. static void sd_close(struct gspca_dev *gspca_dev)
  1266. {
  1267. }
  1268. static void setautogain(struct gspca_dev *gspca_dev)
  1269. {
  1270. struct sd *sd = (struct sd *) gspca_dev;
  1271. /* Thanks S., without your advice, autobright should not work :) */
  1272. int delta;
  1273. int expotimes = 0;
  1274. __u8 luma_mean = 130;
  1275. __u8 luma_delta = 20;
  1276. delta = sd->avg_lum;
  1277. if (delta < luma_mean - luma_delta ||
  1278. delta > luma_mean + luma_delta) {
  1279. switch (sd->sensor) {
  1280. case SENSOR_HV7131R:
  1281. expotimes = sd->exposure >> 8;
  1282. expotimes += (luma_mean - delta) >> 4;
  1283. if (expotimes < 0)
  1284. expotimes = 0;
  1285. sd->exposure = setexposure(gspca_dev,
  1286. (unsigned int) (expotimes << 8));
  1287. break;
  1288. case SENSOR_MO4000:
  1289. case SENSOR_MI0360:
  1290. expotimes = sd->exposure;
  1291. expotimes += (luma_mean - delta) >> 6;
  1292. if (expotimes < 0)
  1293. expotimes = 0;
  1294. sd->exposure = setexposure(gspca_dev,
  1295. (unsigned int) expotimes);
  1296. setcolors(gspca_dev);
  1297. break;
  1298. }
  1299. }
  1300. }
  1301. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1302. struct gspca_frame *frame, /* target */
  1303. unsigned char *data, /* isoc packet */
  1304. int len) /* iso packet length */
  1305. {
  1306. struct sd *sd = (struct sd *) gspca_dev;
  1307. int sof, avg_lum;
  1308. sof = len - 64;
  1309. if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
  1310. /* end of frame */
  1311. gspca_frame_add(gspca_dev, LAST_PACKET,
  1312. frame, data, sof + 2);
  1313. if (sd->ag_cnt < 0)
  1314. return;
  1315. if (--sd->ag_cnt >= 0)
  1316. return;
  1317. sd->ag_cnt = AG_CNT_START;
  1318. /* w1 w2 w3 */
  1319. /* w4 w5 w6 */
  1320. /* w7 w8 */
  1321. /* w4 */
  1322. avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
  1323. /* w6 */
  1324. avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
  1325. /* w2 */
  1326. avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
  1327. /* w8 */
  1328. avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
  1329. /* w5 */
  1330. avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
  1331. avg_lum >>= 4;
  1332. sd->avg_lum = avg_lum;
  1333. PDEBUG(D_PACK, "mean lum %d", avg_lum);
  1334. setautogain(gspca_dev);
  1335. return;
  1336. }
  1337. if (gspca_dev->last_packet_type == LAST_PACKET) {
  1338. /* put the JPEG 422 header */
  1339. jpeg_put_header(gspca_dev, frame, sd->qindex, 0x21);
  1340. }
  1341. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  1342. }
  1343. static unsigned int getexposure(struct gspca_dev *gspca_dev)
  1344. {
  1345. struct sd *sd = (struct sd *) gspca_dev;
  1346. __u8 hexpo, mexpo, lexpo;
  1347. __u8 expo[6];
  1348. switch (sd->sensor) {
  1349. case SENSOR_HV7131R:
  1350. /* read sensor exposure */
  1351. i2c_r5(gspca_dev, 0x25, expo);
  1352. return (expo[0] << 16) | (expo[1] << 8) | expo[2];
  1353. case SENSOR_MI0360:
  1354. /* read sensor exposure */
  1355. i2c_r5(gspca_dev, 0x09, expo);
  1356. return (expo[0] << 8) | expo[1];
  1357. case SENSOR_MO4000:
  1358. i2c_r5(gspca_dev, 0x0e, expo);
  1359. hexpo = 0; /* expo[1] & 0x07; */
  1360. mexpo = 0x40; /* expo[2] &0xff; */
  1361. lexpo = (expo[1] & 0x30) >> 4;
  1362. PDEBUG(D_CONF, "exposure %d",
  1363. (hexpo << 10) | (mexpo << 2) | lexpo);
  1364. return (hexpo << 10) | (mexpo << 2) | lexpo;
  1365. default:
  1366. /* case SENSOR_OV7660: */
  1367. /* read sensor exposure */
  1368. i2c_r5(gspca_dev, 0x04, expo);
  1369. hexpo = expo[3] & 0x2f;
  1370. lexpo = expo[0] & 0x02;
  1371. i2c_r5(gspca_dev, 0x08, expo);
  1372. mexpo = expo[2];
  1373. return (hexpo << 10) | (mexpo << 2) | lexpo;
  1374. }
  1375. }
  1376. static void getbrightness(struct gspca_dev *gspca_dev)
  1377. {
  1378. struct sd *sd = (struct sd *) gspca_dev;
  1379. /* hardcoded registers seem not readable */
  1380. switch (sd->sensor) {
  1381. case SENSOR_HV7131R:
  1382. /* sd->brightness = 0x7fff; */
  1383. sd->brightness = getexposure(gspca_dev) >> 4;
  1384. break;
  1385. case SENSOR_MI0360:
  1386. sd->brightness = getexposure(gspca_dev) << 4;
  1387. break;
  1388. case SENSOR_MO4000:
  1389. /* sd->brightness = 0x1fff; */
  1390. sd->brightness = getexposure(gspca_dev) << 4;
  1391. break;
  1392. }
  1393. }
  1394. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1395. {
  1396. struct sd *sd = (struct sd *) gspca_dev;
  1397. sd->brightness = val;
  1398. if (gspca_dev->streaming)
  1399. setbrightness(gspca_dev);
  1400. return 0;
  1401. }
  1402. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1403. {
  1404. struct sd *sd = (struct sd *) gspca_dev;
  1405. getbrightness(gspca_dev);
  1406. *val = sd->brightness;
  1407. return 0;
  1408. }
  1409. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1410. {
  1411. struct sd *sd = (struct sd *) gspca_dev;
  1412. sd->contrast = val;
  1413. if (gspca_dev->streaming)
  1414. setcontrast(gspca_dev);
  1415. return 0;
  1416. }
  1417. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1418. {
  1419. struct sd *sd = (struct sd *) gspca_dev;
  1420. *val = sd->contrast;
  1421. return 0;
  1422. }
  1423. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1424. {
  1425. struct sd *sd = (struct sd *) gspca_dev;
  1426. sd->colors = val;
  1427. if (gspca_dev->streaming)
  1428. setcolors(gspca_dev);
  1429. return 0;
  1430. }
  1431. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1432. {
  1433. struct sd *sd = (struct sd *) gspca_dev;
  1434. *val = sd->colors;
  1435. return 0;
  1436. }
  1437. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1438. {
  1439. struct sd *sd = (struct sd *) gspca_dev;
  1440. sd->autogain = val;
  1441. if (val)
  1442. sd->ag_cnt = AG_CNT_START;
  1443. else
  1444. sd->ag_cnt = -1;
  1445. return 0;
  1446. }
  1447. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1448. {
  1449. struct sd *sd = (struct sd *) gspca_dev;
  1450. *val = sd->autogain;
  1451. return 0;
  1452. }
  1453. /* sub-driver description */
  1454. static struct sd_desc sd_desc = {
  1455. .name = MODULE_NAME,
  1456. .ctrls = sd_ctrls,
  1457. .nctrls = ARRAY_SIZE(sd_ctrls),
  1458. .config = sd_config,
  1459. .open = sd_open,
  1460. .start = sd_start,
  1461. .stopN = sd_stopN,
  1462. .stop0 = sd_stop0,
  1463. .close = sd_close,
  1464. .pkt_scan = sd_pkt_scan,
  1465. };
  1466. /* -- module initialisation -- */
  1467. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  1468. static __devinitdata struct usb_device_id device_table[] = {
  1469. {USB_DEVICE(0x0458, 0x7025), DVNM("Genius Eye 311Q")},
  1470. {USB_DEVICE(0x045e, 0x00f5), DVNM("MicroSoft VX3000")},
  1471. {USB_DEVICE(0x045e, 0x00f7), DVNM("MicroSoft VX1000")},
  1472. {USB_DEVICE(0x0471, 0x0327), DVNM("Philips SPC 600 NC")},
  1473. {USB_DEVICE(0x0471, 0x0328), DVNM("Philips SPC 700 NC")},
  1474. {USB_DEVICE(0x0471, 0x0330), DVNM("Philips SPC 710NC")},
  1475. {USB_DEVICE(0x0c45, 0x6040), DVNM("Speed NVC 350K")},
  1476. {USB_DEVICE(0x0c45, 0x607c), DVNM("Sonix sn9c102p Hv7131R")},
  1477. {USB_DEVICE(0x0c45, 0x60c0), DVNM("Sangha Sn535")},
  1478. {USB_DEVICE(0x0c45, 0x60ec), DVNM("SN9C105+MO4000")},
  1479. {USB_DEVICE(0x0c45, 0x60fb), DVNM("Surfer NoName")},
  1480. {USB_DEVICE(0x0c45, 0x60fc), DVNM("LG-LIC300")},
  1481. {USB_DEVICE(0x0c45, 0x612a), DVNM("Avant Camera")},
  1482. {USB_DEVICE(0x0c45, 0x612c), DVNM("Typhoon Rasy Cam 1.3MPix")},
  1483. {USB_DEVICE(0x0c45, 0x6130), DVNM("Sonix Pccam")},
  1484. {USB_DEVICE(0x0c45, 0x6138), DVNM("Sn9c120 Mo4000")},
  1485. {USB_DEVICE(0x0c45, 0x613b), DVNM("Surfer SN-206")},
  1486. {USB_DEVICE(0x0c45, 0x613c), DVNM("Sonix Pccam168")},
  1487. {}
  1488. };
  1489. MODULE_DEVICE_TABLE(usb, device_table);
  1490. /* -- device connect -- */
  1491. static int sd_probe(struct usb_interface *intf,
  1492. const struct usb_device_id *id)
  1493. {
  1494. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1495. THIS_MODULE);
  1496. }
  1497. static struct usb_driver sd_driver = {
  1498. .name = MODULE_NAME,
  1499. .id_table = device_table,
  1500. .probe = sd_probe,
  1501. .disconnect = gspca_disconnect,
  1502. };
  1503. /* -- module insert / remove -- */
  1504. static int __init sd_mod_init(void)
  1505. {
  1506. if (usb_register(&sd_driver) < 0)
  1507. return -1;
  1508. info("v%s registered", version);
  1509. return 0;
  1510. }
  1511. static void __exit sd_mod_exit(void)
  1512. {
  1513. usb_deregister(&sd_driver);
  1514. info("deregistered");
  1515. }
  1516. module_init(sd_mod_init);
  1517. module_exit(sd_mod_exit);