sonixj.c 48 KB

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