sonixb.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. /*
  2. * sonix sn9c102 (bayer) library
  3. * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr
  4. * Add Pas106 Stefano Mozzi (C) 2004
  5. *
  6. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #define MODULE_NAME "sonixb"
  23. #include "gspca.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/SN9C102 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. struct sd_desc sd_desc; /* our nctrls differ dependend upon the
  33. sensor, so we use a per cam copy */
  34. atomic_t avg_lum;
  35. unsigned char gain;
  36. unsigned char exposure;
  37. unsigned char brightness;
  38. unsigned char autogain;
  39. unsigned char autogain_ignore_frames;
  40. unsigned char fr_h_sz; /* size of frame header */
  41. char sensor; /* Type of image sensor chip */
  42. char sensor_has_gain;
  43. #define SENSOR_HV7131R 0
  44. #define SENSOR_OV6650 1
  45. #define SENSOR_OV7630 2
  46. #define SENSOR_OV7630_3 3
  47. #define SENSOR_PAS106 4
  48. #define SENSOR_PAS202 5
  49. #define SENSOR_TAS5110 6
  50. #define SENSOR_TAS5130CXX 7
  51. };
  52. #define COMP2 0x8f
  53. #define COMP 0xc7 /* 0x87 //0x07 */
  54. #define COMP1 0xc9 /* 0x89 //0x09 */
  55. #define MCK_INIT 0x63
  56. #define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
  57. #define SYS_CLK 0x04
  58. /* We calculate the autogain at the end of the transfer of a frame, at this
  59. moment a frame with the old settings is being transmitted, and a frame is
  60. being captured with the old settings. So if we adjust the autogain we must
  61. ignore atleast the 2 next frames for the new settings to come into effect
  62. before doing any other adjustments */
  63. #define AUTOGAIN_IGNORE_FRAMES 3
  64. #define AUTOGAIN_DEADZONE 1000
  65. #define DESIRED_AVG_LUM 7000
  66. /* V4L2 controls supported by the driver */
  67. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  68. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  69. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  70. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  71. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  72. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  73. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  74. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  75. static struct ctrl sd_ctrls[] = {
  76. {
  77. {
  78. .id = V4L2_CID_BRIGHTNESS,
  79. .type = V4L2_CTRL_TYPE_INTEGER,
  80. .name = "Brightness",
  81. .minimum = 0,
  82. .maximum = 255,
  83. .step = 1,
  84. #define BRIGHTNESS_DEF 127
  85. .default_value = BRIGHTNESS_DEF,
  86. },
  87. .set = sd_setbrightness,
  88. .get = sd_getbrightness,
  89. },
  90. {
  91. {
  92. .id = V4L2_CID_GAIN,
  93. .type = V4L2_CTRL_TYPE_INTEGER,
  94. .name = "Gain",
  95. .minimum = 0,
  96. .maximum = 255,
  97. .step = 1,
  98. #define GAIN_DEF 127
  99. #define GAIN_KNEE 200
  100. .default_value = GAIN_DEF,
  101. },
  102. .set = sd_setgain,
  103. .get = sd_getgain,
  104. },
  105. {
  106. {
  107. .id = V4L2_CID_EXPOSURE,
  108. .type = V4L2_CTRL_TYPE_INTEGER,
  109. .name = "Exposure",
  110. #define EXPOSURE_DEF 0
  111. #define EXPOSURE_KNEE 176 /* 10 fps */
  112. .minimum = 0,
  113. .maximum = 255,
  114. .step = 1,
  115. .default_value = EXPOSURE_DEF,
  116. .flags = 0,
  117. },
  118. .set = sd_setexposure,
  119. .get = sd_getexposure,
  120. },
  121. {
  122. {
  123. .id = V4L2_CID_AUTOGAIN,
  124. .type = V4L2_CTRL_TYPE_BOOLEAN,
  125. .name = "Automatic Gain (and Exposure)",
  126. .minimum = 0,
  127. .maximum = 1,
  128. .step = 1,
  129. #define AUTOGAIN_DEF 1
  130. .default_value = AUTOGAIN_DEF,
  131. .flags = 0,
  132. },
  133. .set = sd_setautogain,
  134. .get = sd_getautogain,
  135. },
  136. };
  137. static struct v4l2_pix_format vga_mode[] = {
  138. {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  139. .bytesperline = 160,
  140. .sizeimage = 160 * 120,
  141. .colorspace = V4L2_COLORSPACE_SRGB,
  142. .priv = 2},
  143. {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  144. .bytesperline = 320,
  145. .sizeimage = 320 * 240,
  146. .colorspace = V4L2_COLORSPACE_SRGB,
  147. .priv = 1},
  148. {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  149. .bytesperline = 640,
  150. .sizeimage = 640 * 480,
  151. .colorspace = V4L2_COLORSPACE_SRGB,
  152. .priv = 0},
  153. };
  154. static struct v4l2_pix_format sif_mode[] = {
  155. {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  156. .bytesperline = 176,
  157. .sizeimage = 176 * 144,
  158. .colorspace = V4L2_COLORSPACE_SRGB,
  159. .priv = 1},
  160. {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  161. .bytesperline = 352,
  162. .sizeimage = 352 * 288,
  163. .colorspace = V4L2_COLORSPACE_SRGB,
  164. .priv = 0},
  165. };
  166. static const __u8 probe_ov7630[] = {0x08, 0x44};
  167. static const __u8 initHv7131[] = {
  168. 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
  169. 0x00, 0x00,
  170. 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* shift from 0x02 0x01 0x00 */
  171. 0x28, 0x1e, 0x60, 0x8a, 0x20,
  172. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c
  173. };
  174. static const __u8 hv7131_sensor_init[][8] = {
  175. {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
  176. {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
  177. {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
  178. {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
  179. {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
  180. };
  181. static const __u8 initOv6650[] = {
  182. 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  183. 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  184. 0x00, 0x02, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x0b,
  185. 0x10, 0x1d, 0x10, 0x00, 0x06, 0x1f, 0x00
  186. };
  187. static const __u8 ov6650_sensor_init[][8] =
  188. {
  189. /* Bright, contrast, etc are set througth SCBB interface.
  190. * AVCAP on win2 do not send any data on this controls. */
  191. /* Anyway, some registers appears to alter bright and constrat */
  192. /* Reset sensor */
  193. {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  194. /* Set clock register 0x11 low nibble is clock divider */
  195. {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
  196. /* Next some unknown stuff */
  197. {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
  198. /* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},
  199. * THIS SET GREEN SCREEN
  200. * (pixels could be innverted in decode kind of "brg",
  201. * but blue wont be there. Avoid this data ... */
  202. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
  203. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
  204. {0xa0, 0x60, 0x30, 0x3d, 0x0A, 0xd8, 0xa4, 0x10},
  205. /* Disable autobright ? */
  206. {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10},
  207. /* Some more unknown stuff */
  208. {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
  209. {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */
  210. {0xa0, 0x60, 0x10, 0x57, 0x99, 0x04, 0x94, 0x16},
  211. /* Framerate adjust register for artificial light 50 hz flicker
  212. compensation, identical to ov6630 0x2b register, see 6630 datasheet.
  213. 0x4f -> (30 fps -> 25 fps), 0x00 -> no adjustment */
  214. {0xa0, 0x60, 0x2b, 0x4f, 0x99, 0x04, 0x94, 0x15},
  215. };
  216. static const __u8 initOv7630[] = {
  217. 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */
  218. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
  219. 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */
  220. 0x28, 0x1e, /* H & V sizes r15 .. r16 */
  221. 0x68, COMP1, MCK_INIT1, /* r17 .. r19 */
  222. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c /* r1a .. r1f */
  223. };
  224. static const __u8 initOv7630_3[] = {
  225. 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */
  226. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, /* r09 .. r10 */
  227. 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */
  228. 0x16, 0x12, /* H & V sizes r15 .. r16 */
  229. 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */
  230. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c, 0x00, /* r1a .. r20 */
  231. 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, /* r21 .. r28 */
  232. 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff /* r29 .. r30 */
  233. };
  234. static const __u8 ov7630_sensor_init_com[][8] = {
  235. {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  236. {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
  237. /* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
  238. {0xd0, 0x21, 0x12, 0x78, 0x00, 0x80, 0x34, 0x10}, /* jfm */
  239. {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
  240. {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
  241. {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
  242. {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
  243. {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
  244. {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
  245. {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
  246. /* {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10}, jfm */
  247. {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, /* jfm */
  248. {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
  249. {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
  250. {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
  251. {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
  252. {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
  253. {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
  254. };
  255. static const __u8 ov7630_sensor_init[][8] = {
  256. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 200ms */
  257. {0xa0, 0x21, 0x11, 0x01, 0xbd, 0x06, 0xf6, 0x10}, /* jfm */
  258. {0xa0, 0x21, 0x10, 0x57, 0xbd, 0x06, 0xf6, 0x16},
  259. {0xa0, 0x21, 0x76, 0x02, 0xbd, 0x06, 0xf6, 0x16},
  260. {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
  261. };
  262. static const __u8 ov7630_sensor_init_3[][5][8] = {
  263. { {0xa0, 0x21, 0x10, 0x36, 0xbd, 0x06, 0xf6, 0x16}, /* exposure */
  264. {0xa0, 0x21, 0x76, 0x03, 0xbd, 0x06, 0xf6, 0x16},
  265. {0xa0, 0x21, 0x11, 0x01, 0xbd, 0x06, 0xf6, 0x16},
  266. {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
  267. {0xb0, 0x21, 0x2a, 0xa0, 0x1c, 0x06, 0xf6, 0x1d},
  268. },
  269. { {0xa0, 0x21, 0x10, 0x83, 0xbd, 0x06, 0xf6, 0x16}, /* exposure */
  270. {0xa0, 0x21, 0x76, 0x00, 0xbd, 0x06, 0xf6, 0x16},
  271. {0xa0, 0x21, 0x11, 0x00, 0xbd, 0x06, 0xf6, 0x16},
  272. {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
  273. /* {0xb0, 0x21, 0x2a, 0xc0, 0x3c, 0x06, 0xf6, 0x1d},
  274. * a0 1c,a0 1f,c0 3c frame rate ?line interval from ov6630 */
  275. /* {0xb0, 0x21, 0x2a, 0xa0, 0x1f, 0x06, 0xf6, 0x1d}, * from win */
  276. {0xb0, 0x21, 0x2a, 0x80, 0x60, 0x06, 0xf6, 0x1d},
  277. }
  278. };
  279. static const __u8 initPas106[] = {
  280. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
  281. 0x00, 0x00,
  282. 0x00, 0x00, 0x00, 0x05, 0x01, 0x00,
  283. 0x16, 0x12, 0x28, COMP1, MCK_INIT1,
  284. 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
  285. };
  286. /* compression 0x86 mckinit1 0x2b */
  287. static const __u8 pas106_data[][2] = {
  288. {0x02, 0x04}, /* Pixel Clock Divider 6 */
  289. {0x03, 0x13}, /* Frame Time MSB */
  290. /* {0x03, 0x12}, * Frame Time MSB */
  291. {0x04, 0x06}, /* Frame Time LSB */
  292. /* {0x04, 0x05}, * Frame Time LSB */
  293. {0x05, 0x65}, /* Shutter Time Line Offset */
  294. /* {0x05, 0x6d}, * Shutter Time Line Offset */
  295. /* {0x06, 0xb1}, * Shutter Time Pixel Offset */
  296. {0x06, 0xcd}, /* Shutter Time Pixel Offset */
  297. {0x07, 0xc1}, /* Black Level Subtract Sign */
  298. /* {0x07, 0x00}, * Black Level Subtract Sign */
  299. {0x08, 0x06}, /* Black Level Subtract Level */
  300. {0x08, 0x06}, /* Black Level Subtract Level */
  301. /* {0x08, 0x01}, * Black Level Subtract Level */
  302. {0x09, 0x05}, /* Color Gain B Pixel 5 a */
  303. {0x0a, 0x04}, /* Color Gain G1 Pixel 1 5 */
  304. {0x0b, 0x04}, /* Color Gain G2 Pixel 1 0 5 */
  305. {0x0c, 0x05}, /* Color Gain R Pixel 3 1 */
  306. {0x0d, 0x00}, /* Color GainH Pixel */
  307. {0x0e, 0x0e}, /* Global Gain */
  308. {0x0f, 0x00}, /* Contrast */
  309. {0x10, 0x06}, /* H&V synchro polarity */
  310. {0x11, 0x06}, /* ?default */
  311. {0x12, 0x06}, /* DAC scale */
  312. {0x14, 0x02}, /* ?default */
  313. {0x13, 0x01}, /* Validate Settings */
  314. };
  315. static const __u8 initPas202[] = {
  316. 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
  317. 0x00, 0x00,
  318. 0x00, 0x00, 0x00, 0x07, 0x03, 0x0a, /* 6 */
  319. 0x28, 0x1e, 0x28, 0x89, 0x30,
  320. 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c
  321. };
  322. static const __u8 pas202_sensor_init[][8] = {
  323. {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10},
  324. {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
  325. {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
  326. {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x00, 0x32, 0x10},
  327. {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
  328. {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
  329. {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
  330. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  331. {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
  332. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  333. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x10},
  334. {0xb0, 0x40, 0x0e, 0x00, 0x3d, 0x00, 0x63, 0x10},
  335. {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
  336. {0xa0, 0x40, 0x10, 0x08, 0x3d, 0x00, 0x63, 0x15},
  337. {0xa0, 0x40, 0x02, 0x04, 0x3d, 0x00, 0x63, 0x16},
  338. {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
  339. {0xb0, 0x40, 0x0e, 0x00, 0x31, 0x00, 0x63, 0x16},
  340. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
  341. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15},
  342. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
  343. };
  344. static const __u8 initTas5110[] = {
  345. 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  346. 0x00, 0x00,
  347. 0x00, 0x01, 0x00, 0x46, 0x09, 0x0a, /* shift from 0x45 0x09 0x0a */
  348. 0x16, 0x12, 0x60, 0x86, 0x2b,
  349. 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
  350. };
  351. static const __u8 tas5110_sensor_init[][8] = {
  352. {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
  353. {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
  354. {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17},
  355. };
  356. static const __u8 initTas5130[] = {
  357. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  358. 0x00, 0x00,
  359. 0x00, 0x01, 0x00, 0x69, 0x0c, 0x0a,
  360. 0x28, 0x1e, 0x60, COMP, MCK_INIT,
  361. 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
  362. };
  363. static const __u8 tas5130_sensor_init[][8] = {
  364. /* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10},
  365. * shutter 0x47 short exposure? */
  366. {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
  367. /* shutter 0x01 long exposure */
  368. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
  369. };
  370. /* get one byte in gspca_dev->usb_buf */
  371. static void reg_r(struct gspca_dev *gspca_dev,
  372. __u16 value)
  373. {
  374. usb_control_msg(gspca_dev->dev,
  375. usb_rcvctrlpipe(gspca_dev->dev, 0),
  376. 0, /* request */
  377. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  378. value,
  379. 0, /* index */
  380. gspca_dev->usb_buf, 1,
  381. 500);
  382. }
  383. static void reg_w(struct gspca_dev *gspca_dev,
  384. __u16 value,
  385. const __u8 *buffer,
  386. int len)
  387. {
  388. #ifdef CONFIG_VIDEO_ADV_DEBUG
  389. if (len > sizeof gspca_dev->usb_buf) {
  390. PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow");
  391. return;
  392. }
  393. #endif
  394. memcpy(gspca_dev->usb_buf, buffer, len);
  395. usb_control_msg(gspca_dev->dev,
  396. usb_sndctrlpipe(gspca_dev->dev, 0),
  397. 0x08, /* request */
  398. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  399. value,
  400. 0, /* index */
  401. gspca_dev->usb_buf, len,
  402. 500);
  403. }
  404. static void reg_w_big(struct gspca_dev *gspca_dev,
  405. __u16 value,
  406. const __u8 *buffer,
  407. int len)
  408. {
  409. __u8 *tmpbuf;
  410. tmpbuf = kmalloc(len, GFP_KERNEL);
  411. memcpy(tmpbuf, buffer, len);
  412. usb_control_msg(gspca_dev->dev,
  413. usb_sndctrlpipe(gspca_dev->dev, 0),
  414. 0x08, /* request */
  415. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  416. value,
  417. 0, /* index */
  418. tmpbuf, len,
  419. 500);
  420. kfree(tmpbuf);
  421. }
  422. static int i2c_w(struct gspca_dev *gspca_dev, const __u8 *buffer)
  423. {
  424. int retry = 60;
  425. /* is i2c ready */
  426. reg_w(gspca_dev, 0x08, buffer, 8);
  427. while (retry--) {
  428. msleep(10);
  429. reg_r(gspca_dev, 0x08);
  430. if (gspca_dev->usb_buf[0] == 4)
  431. return 0;
  432. }
  433. return -1;
  434. }
  435. static void i2c_w_vector(struct gspca_dev *gspca_dev,
  436. const __u8 buffer[][8], int len)
  437. {
  438. for (;;) {
  439. reg_w(gspca_dev, 0x08, *buffer, 8);
  440. len -= 8;
  441. if (len <= 0)
  442. break;
  443. buffer++;
  444. }
  445. }
  446. static void setbrightness(struct gspca_dev *gspca_dev)
  447. {
  448. struct sd *sd = (struct sd *) gspca_dev;
  449. __u8 value;
  450. switch (sd->sensor) {
  451. case SENSOR_OV6650: {
  452. __u8 i2cOV6650[] =
  453. {0xa0, 0x60, 0x06, 0x11, 0x99, 0x04, 0x94, 0x15};
  454. i2cOV6650[3] = sd->brightness;
  455. if (i2c_w(gspca_dev, i2cOV6650) < 0)
  456. goto err;
  457. break;
  458. }
  459. case SENSOR_OV7630: {
  460. __u8 i2cOV[] =
  461. {0xa0, 0x21, 0x06, 0x36, 0xbd, 0x06, 0xf6, 0x16};
  462. /* change reg 0x06 */
  463. i2cOV[3] = sd->brightness;
  464. if (i2c_w(gspca_dev, i2cOV) < 0)
  465. goto err;
  466. break;
  467. }
  468. case SENSOR_PAS106: {
  469. __u8 i2c1[] =
  470. {0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
  471. i2c1[3] = sd->brightness >> 3;
  472. i2c1[2] = 0x0e;
  473. if (i2c_w(gspca_dev, i2c1) < 0)
  474. goto err;
  475. i2c1[3] = 0x01;
  476. i2c1[2] = 0x13;
  477. if (i2c_w(gspca_dev, i2c1) < 0)
  478. goto err;
  479. break;
  480. }
  481. case SENSOR_PAS202: {
  482. /* __u8 i2cpexpo1[] =
  483. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x16}; */
  484. __u8 i2cpexpo[] =
  485. {0xb0, 0x40, 0x0e, 0x01, 0xab, 0x00, 0x63, 0x16};
  486. __u8 i2cp202[] =
  487. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15};
  488. static __u8 i2cpdoit[] =
  489. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16};
  490. /* change reg 0x10 */
  491. i2cpexpo[4] = 0xff - sd->brightness;
  492. /* if(i2c_w(gspca_dev,i2cpexpo1) < 0)
  493. goto err; */
  494. /* if(i2c_w(gspca_dev,i2cpdoit) < 0)
  495. goto err; */
  496. if (i2c_w(gspca_dev, i2cpexpo) < 0)
  497. goto err;
  498. if (i2c_w(gspca_dev, i2cpdoit) < 0)
  499. goto err;
  500. i2cp202[3] = sd->brightness >> 3;
  501. if (i2c_w(gspca_dev, i2cp202) < 0)
  502. goto err;
  503. if (i2c_w(gspca_dev, i2cpdoit) < 0)
  504. goto err;
  505. break;
  506. }
  507. case SENSOR_TAS5130CXX: {
  508. __u8 i2c[] =
  509. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  510. value = 0xff - sd->brightness;
  511. i2c[4] = value;
  512. PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]);
  513. if (i2c_w(gspca_dev, i2c) < 0)
  514. goto err;
  515. break;
  516. }
  517. case SENSOR_TAS5110:
  518. /* FIXME figure out howto control brightness on TAS5110 */
  519. break;
  520. }
  521. return;
  522. err:
  523. PDEBUG(D_ERR, "i2c error brightness");
  524. }
  525. static void setsensorgain(struct gspca_dev *gspca_dev)
  526. {
  527. struct sd *sd = (struct sd *) gspca_dev;
  528. switch (sd->sensor) {
  529. case SENSOR_TAS5110: {
  530. __u8 i2c[] =
  531. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  532. i2c[4] = 255 - sd->gain;
  533. if (i2c_w(gspca_dev, i2c) < 0)
  534. goto err;
  535. break;
  536. }
  537. case SENSOR_OV6650: {
  538. __u8 i2c[] = {0xa0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
  539. i2c[3] = sd->gain >> 3;
  540. if (i2c_w(gspca_dev, i2c) < 0)
  541. goto err;
  542. break;
  543. }
  544. }
  545. return;
  546. err:
  547. PDEBUG(D_ERR, "i2c error gain");
  548. }
  549. static void setgain(struct gspca_dev *gspca_dev)
  550. {
  551. struct sd *sd = (struct sd *) gspca_dev;
  552. __u8 gain;
  553. __u8 rgb_value;
  554. gain = sd->gain >> 4;
  555. /* red and blue gain */
  556. rgb_value = gain << 4 | gain;
  557. reg_w(gspca_dev, 0x10, &rgb_value, 1);
  558. /* green gain */
  559. rgb_value = gain;
  560. reg_w(gspca_dev, 0x11, &rgb_value, 1);
  561. if (sd->sensor_has_gain)
  562. setsensorgain(gspca_dev);
  563. }
  564. static void setexposure(struct gspca_dev *gspca_dev)
  565. {
  566. struct sd *sd = (struct sd *) gspca_dev;
  567. /* translate 0 - 255 to a number of fps in a 30 - 1 scale */
  568. int fps = 30 - sd->exposure * 29 / 255;
  569. switch (sd->sensor) {
  570. case SENSOR_TAS5110: {
  571. __u8 reg;
  572. /* register 19's high nibble contains the sn9c10x clock divider
  573. The high nibble configures the no fps according to the
  574. formula: 60 / high_nibble. With a maximum of 30 fps */
  575. reg = 60 / fps;
  576. if (reg > 15)
  577. reg = 15;
  578. reg = (reg << 4) | 0x0b;
  579. reg_w(gspca_dev, 0x19, &reg, 1);
  580. break;
  581. }
  582. case SENSOR_OV6650: {
  583. __u8 i2c[] = {0xa0, 0x60, 0x11, 0xc0, 0x00, 0x00, 0x00, 0x10};
  584. i2c[3] = 30 / fps - 1;
  585. if (i2c[3] > 15)
  586. i2c[3] = 15;
  587. i2c[3] |= 0xc0;
  588. if (i2c_w(gspca_dev, i2c) < 0)
  589. PDEBUG(D_ERR, "i2c error exposure");
  590. break;
  591. }
  592. }
  593. }
  594. static void do_autogain(struct gspca_dev *gspca_dev)
  595. {
  596. struct sd *sd = (struct sd *) gspca_dev;
  597. int avg_lum = atomic_read(&sd->avg_lum);
  598. if (avg_lum == -1)
  599. return;
  600. if (sd->autogain_ignore_frames > 0)
  601. sd->autogain_ignore_frames--;
  602. else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
  603. sd->brightness * DESIRED_AVG_LUM / 127,
  604. AUTOGAIN_DEADZONE, GAIN_KNEE, EXPOSURE_KNEE))
  605. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  606. }
  607. /* this function is called at probe time */
  608. static int sd_config(struct gspca_dev *gspca_dev,
  609. const struct usb_device_id *id)
  610. {
  611. struct sd *sd = (struct sd *) gspca_dev;
  612. struct cam *cam;
  613. __u16 product;
  614. int sif = 0;
  615. /* nctrls depends upon the sensor, so we use a per cam copy */
  616. memcpy(&sd->sd_desc, gspca_dev->sd_desc, sizeof(struct sd_desc));
  617. gspca_dev->sd_desc = &sd->sd_desc;
  618. sd->fr_h_sz = 12; /* default size of the frame header */
  619. sd->sd_desc.nctrls = 2; /* default nb of ctrls */
  620. product = id->idProduct;
  621. /* switch (id->idVendor) { */
  622. /* case 0x0c45: * Sonix */
  623. switch (product) {
  624. case 0x6001: /* SN9C102 */
  625. case 0x6005: /* SN9C101 */
  626. case 0x6007: /* SN9C101 */
  627. sd->sensor = SENSOR_TAS5110;
  628. sd->sensor_has_gain = 1;
  629. sd->sd_desc.nctrls = 4;
  630. sd->sd_desc.dq_callback = do_autogain;
  631. sif = 1;
  632. break;
  633. case 0x6009: /* SN9C101 */
  634. case 0x600d: /* SN9C101 */
  635. case 0x6029: /* SN9C101 */
  636. sd->sensor = SENSOR_PAS106;
  637. sif = 1;
  638. break;
  639. case 0x6011: /* SN9C101 - SN9C101G */
  640. sd->sensor = SENSOR_OV6650;
  641. sd->sensor_has_gain = 1;
  642. sd->sd_desc.nctrls = 4;
  643. sd->sd_desc.dq_callback = do_autogain;
  644. sif = 1;
  645. break;
  646. case 0x6019: /* SN9C101 */
  647. case 0x602c: /* SN9C102 */
  648. case 0x602e: /* SN9C102 */
  649. sd->sensor = SENSOR_OV7630;
  650. break;
  651. case 0x60b0: /* SN9C103 */
  652. sd->sensor = SENSOR_OV7630_3;
  653. sd->fr_h_sz = 18; /* size of frame header */
  654. break;
  655. case 0x6024: /* SN9C102 */
  656. case 0x6025: /* SN9C102 */
  657. sd->sensor = SENSOR_TAS5130CXX;
  658. break;
  659. case 0x6028: /* SN9C102 */
  660. sd->sensor = SENSOR_PAS202;
  661. break;
  662. case 0x602d: /* SN9C102 */
  663. sd->sensor = SENSOR_HV7131R;
  664. break;
  665. case 0x60af: /* SN9C103 */
  666. sd->sensor = SENSOR_PAS202;
  667. sd->fr_h_sz = 18; /* size of frame header (?) */
  668. break;
  669. }
  670. /* break; */
  671. /* } */
  672. cam = &gspca_dev->cam;
  673. cam->dev_name = (char *) id->driver_info;
  674. cam->epaddr = 0x01;
  675. if (!sif) {
  676. cam->cam_mode = vga_mode;
  677. cam->nmodes = ARRAY_SIZE(vga_mode);
  678. if (sd->sensor == SENSOR_OV7630_3) {
  679. /* We only have 320x240 & 640x480 */
  680. cam->cam_mode++;
  681. cam->nmodes--;
  682. }
  683. } else {
  684. cam->cam_mode = sif_mode;
  685. cam->nmodes = ARRAY_SIZE(sif_mode);
  686. }
  687. sd->brightness = BRIGHTNESS_DEF;
  688. sd->gain = GAIN_DEF;
  689. sd->exposure = EXPOSURE_DEF;
  690. sd->autogain = AUTOGAIN_DEF;
  691. if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */
  692. reg_w(gspca_dev, 0x01, probe_ov7630, sizeof probe_ov7630);
  693. return 0;
  694. }
  695. /* this function is called at open time */
  696. static int sd_open(struct gspca_dev *gspca_dev)
  697. {
  698. reg_r(gspca_dev, 0x00);
  699. if (gspca_dev->usb_buf[0] != 0x10)
  700. return -ENODEV;
  701. return 0;
  702. }
  703. static void pas106_i2cinit(struct gspca_dev *gspca_dev)
  704. {
  705. int i;
  706. const __u8 *data;
  707. __u8 i2c1[] = { 0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 };
  708. i = ARRAY_SIZE(pas106_data);
  709. data = pas106_data[0];
  710. while (--i >= 0) {
  711. memcpy(&i2c1[2], data, 2);
  712. /* copy 2 bytes from the template */
  713. if (i2c_w(gspca_dev, i2c1) < 0)
  714. PDEBUG(D_ERR, "i2c error pas106");
  715. data += 2;
  716. }
  717. }
  718. /* -- start the camera -- */
  719. static void sd_start(struct gspca_dev *gspca_dev)
  720. {
  721. struct sd *sd = (struct sd *) gspca_dev;
  722. int mode, l;
  723. const __u8 *sn9c10x;
  724. __u8 reg01, reg17;
  725. __u8 reg17_19[3];
  726. static const __u8 reg15[2] = { 0x28, 0x1e };
  727. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  728. switch (sd->sensor) {
  729. case SENSOR_HV7131R:
  730. sn9c10x = initHv7131;
  731. reg17_19[0] = 0x60;
  732. reg17_19[1] = (mode << 4) | 0x8a;
  733. reg17_19[2] = 0x20;
  734. break;
  735. case SENSOR_OV6650:
  736. sn9c10x = initOv6650;
  737. reg17_19[0] = 0x68;
  738. reg17_19[1] = (mode << 4) | 0x8b;
  739. reg17_19[2] = 0x20;
  740. break;
  741. case SENSOR_OV7630:
  742. sn9c10x = initOv7630;
  743. reg17_19[0] = 0x68;
  744. reg17_19[1] = (mode << 4) | COMP2;
  745. reg17_19[2] = MCK_INIT1;
  746. break;
  747. case SENSOR_OV7630_3:
  748. sn9c10x = initOv7630_3;
  749. reg17_19[0] = 0x68;
  750. reg17_19[1] = (mode << 4) | COMP2;
  751. reg17_19[2] = MCK_INIT1;
  752. break;
  753. case SENSOR_PAS106:
  754. sn9c10x = initPas106;
  755. reg17_19[0] = 0x24; /* 0x28 */
  756. reg17_19[1] = (mode << 4) | COMP1;
  757. reg17_19[2] = MCK_INIT1;
  758. break;
  759. case SENSOR_PAS202:
  760. sn9c10x = initPas202;
  761. reg17_19[0] = mode ? 0x24 : 0x20;
  762. reg17_19[1] = (mode << 4) | 0x89;
  763. reg17_19[2] = 0x20;
  764. break;
  765. case SENSOR_TAS5110:
  766. sn9c10x = initTas5110;
  767. reg17_19[0] = 0x60;
  768. reg17_19[1] = (mode << 4) | 0x86;
  769. reg17_19[2] = 0x2b; /* 0xf3; */
  770. break;
  771. default:
  772. /* case SENSOR_TAS5130CXX: */
  773. sn9c10x = initTas5130;
  774. reg17_19[0] = 0x60;
  775. reg17_19[1] = (mode << 4) | COMP;
  776. reg17_19[2] = mode ? 0x23 : 0x43;
  777. break;
  778. }
  779. switch (sd->sensor) {
  780. case SENSOR_OV7630:
  781. reg01 = 0x06;
  782. reg17 = 0x29;
  783. l = 0x10;
  784. break;
  785. case SENSOR_OV7630_3:
  786. reg01 = 0x44;
  787. reg17 = 0x68;
  788. l = sizeof initOv7630_3;
  789. break;
  790. default:
  791. reg01 = sn9c10x[0];
  792. reg17 = sn9c10x[0x17 - 1];
  793. l = 0x1f;
  794. break;
  795. }
  796. /* reg 0x01 bit 2 video transfert on */
  797. reg_w(gspca_dev, 0x01, &reg01, 1);
  798. /* reg 0x17 SensorClk enable inv Clk 0x60 */
  799. reg_w(gspca_dev, 0x17, &reg17, 1);
  800. /*fixme: for ov7630 102
  801. reg_w(gspca_dev, 0x01, {0x06, sn9c10x[1]}, 2); */
  802. /* Set the registers from the template */
  803. reg_w_big(gspca_dev, 0x01, sn9c10x, l);
  804. switch (sd->sensor) {
  805. case SENSOR_HV7131R:
  806. i2c_w_vector(gspca_dev, hv7131_sensor_init,
  807. sizeof hv7131_sensor_init);
  808. break;
  809. case SENSOR_OV6650:
  810. i2c_w_vector(gspca_dev, ov6650_sensor_init,
  811. sizeof ov6650_sensor_init);
  812. break;
  813. case SENSOR_OV7630:
  814. i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
  815. sizeof ov7630_sensor_init_com);
  816. msleep(200);
  817. i2c_w_vector(gspca_dev, ov7630_sensor_init,
  818. sizeof ov7630_sensor_init);
  819. break;
  820. case SENSOR_OV7630_3:
  821. i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
  822. sizeof ov7630_sensor_init_com);
  823. msleep(200);
  824. i2c_w_vector(gspca_dev, ov7630_sensor_init_3[mode],
  825. sizeof ov7630_sensor_init_3[mode]);
  826. break;
  827. case SENSOR_PAS106:
  828. pas106_i2cinit(gspca_dev);
  829. break;
  830. case SENSOR_PAS202:
  831. i2c_w_vector(gspca_dev, pas202_sensor_init,
  832. sizeof pas202_sensor_init);
  833. break;
  834. case SENSOR_TAS5110:
  835. i2c_w_vector(gspca_dev, tas5110_sensor_init,
  836. sizeof tas5110_sensor_init);
  837. break;
  838. default:
  839. /* case SENSOR_TAS5130CXX: */
  840. i2c_w_vector(gspca_dev, tas5130_sensor_init,
  841. sizeof tas5130_sensor_init);
  842. break;
  843. }
  844. /* H_size V_size 0x28, 0x1e maybe 640x480 */
  845. reg_w(gspca_dev, 0x15, reg15, 2);
  846. /* compression register */
  847. reg_w(gspca_dev, 0x18, &reg17_19[1], 1);
  848. if (sd->sensor != SENSOR_OV7630_3) {
  849. /* H_start */
  850. reg_w(gspca_dev, 0x12, &sn9c10x[0x12 - 1], 1);
  851. /* V_START */
  852. reg_w(gspca_dev, 0x13, &sn9c10x[0x13 - 1], 1);
  853. }
  854. /* reset 0x17 SensorClk enable inv Clk 0x60 */
  855. /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
  856. reg_w(gspca_dev, 0x17, &reg17_19[0], 1);
  857. /*MCKSIZE ->3 */ /*fixme: not ov7630*/
  858. if (sd->sensor != SENSOR_OV7630_3)
  859. reg_w(gspca_dev, 0x19, &reg17_19[2], 1);
  860. /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
  861. reg_w(gspca_dev, 0x1c, &sn9c10x[0x1c - 1], 4);
  862. /* Enable video transfert */
  863. reg_w(gspca_dev, 0x01, &sn9c10x[0], 1);
  864. /* Compression */
  865. reg_w(gspca_dev, 0x18, &reg17_19[1], 2);
  866. msleep(20);
  867. setgain(gspca_dev);
  868. setbrightness(gspca_dev);
  869. setexposure(gspca_dev);
  870. sd->autogain_ignore_frames = 0;
  871. atomic_set(&sd->avg_lum, -1);
  872. }
  873. static void sd_stopN(struct gspca_dev *gspca_dev)
  874. {
  875. __u8 ByteSend;
  876. ByteSend = 0x09; /* 0X00 */
  877. reg_w(gspca_dev, 0x01, &ByteSend, 1);
  878. }
  879. static void sd_stop0(struct gspca_dev *gspca_dev)
  880. {
  881. }
  882. static void sd_close(struct gspca_dev *gspca_dev)
  883. {
  884. }
  885. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  886. struct gspca_frame *frame, /* target */
  887. unsigned char *data, /* isoc packet */
  888. int len) /* iso packet length */
  889. {
  890. int i;
  891. struct sd *sd = (struct sd *) gspca_dev;
  892. if (len > 6 && len < 24) {
  893. for (i = 0; i < len - 6; i++) {
  894. if (data[0 + i] == 0xff
  895. && data[1 + i] == 0xff
  896. && data[2 + i] == 0x00
  897. && data[3 + i] == 0xc4
  898. && data[4 + i] == 0xc4
  899. && data[5 + i] == 0x96) { /* start of frame */
  900. frame = gspca_frame_add(gspca_dev, LAST_PACKET,
  901. frame, data, 0);
  902. if (i < (len - 10)) {
  903. atomic_set(&sd->avg_lum, data[i + 8] +
  904. (data[i + 9] << 8));
  905. } else {
  906. atomic_set(&sd->avg_lum, -1);
  907. #ifdef CONFIG_VIDEO_ADV_DEBUG
  908. PDEBUG(D_STREAM, "packet too short to "
  909. "get avg brightness");
  910. #endif
  911. }
  912. data += i + sd->fr_h_sz;
  913. len -= i + sd->fr_h_sz;
  914. gspca_frame_add(gspca_dev, FIRST_PACKET,
  915. frame, data, len);
  916. return;
  917. }
  918. }
  919. }
  920. gspca_frame_add(gspca_dev, INTER_PACKET,
  921. frame, data, len);
  922. }
  923. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  924. {
  925. struct sd *sd = (struct sd *) gspca_dev;
  926. sd->brightness = val;
  927. if (gspca_dev->streaming)
  928. setbrightness(gspca_dev);
  929. return 0;
  930. }
  931. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  932. {
  933. struct sd *sd = (struct sd *) gspca_dev;
  934. *val = sd->brightness;
  935. return 0;
  936. }
  937. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  938. {
  939. struct sd *sd = (struct sd *) gspca_dev;
  940. sd->gain = val;
  941. if (gspca_dev->streaming)
  942. setgain(gspca_dev);
  943. return 0;
  944. }
  945. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  946. {
  947. struct sd *sd = (struct sd *) gspca_dev;
  948. *val = sd->gain;
  949. return 0;
  950. }
  951. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  952. {
  953. struct sd *sd = (struct sd *) gspca_dev;
  954. sd->exposure = val;
  955. if (gspca_dev->streaming)
  956. setexposure(gspca_dev);
  957. return 0;
  958. }
  959. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  960. {
  961. struct sd *sd = (struct sd *) gspca_dev;
  962. *val = sd->exposure;
  963. return 0;
  964. }
  965. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  966. {
  967. struct sd *sd = (struct sd *) gspca_dev;
  968. sd->autogain = val;
  969. /* when switching to autogain set defaults to make sure
  970. we are on a valid point of the autogain gain /
  971. exposure knee graph, and give this change time to
  972. take effect before doing autogain. */
  973. if (sd->autogain) {
  974. sd->exposure = EXPOSURE_DEF;
  975. sd->gain = GAIN_DEF;
  976. if (gspca_dev->streaming) {
  977. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  978. setexposure(gspca_dev);
  979. setgain(gspca_dev);
  980. }
  981. }
  982. return 0;
  983. }
  984. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  985. {
  986. struct sd *sd = (struct sd *) gspca_dev;
  987. *val = sd->autogain;
  988. return 0;
  989. }
  990. /* sub-driver description */
  991. static const struct sd_desc sd_desc = {
  992. .name = MODULE_NAME,
  993. .ctrls = sd_ctrls,
  994. .nctrls = ARRAY_SIZE(sd_ctrls),
  995. .config = sd_config,
  996. .open = sd_open,
  997. .start = sd_start,
  998. .stopN = sd_stopN,
  999. .stop0 = sd_stop0,
  1000. .close = sd_close,
  1001. .pkt_scan = sd_pkt_scan,
  1002. };
  1003. /* -- module initialisation -- */
  1004. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  1005. static __devinitdata struct usb_device_id device_table[] = {
  1006. #ifndef CONFIG_USB_SN9C102
  1007. {USB_DEVICE(0x0c45, 0x6001), DVNM("Genius VideoCAM NB")},
  1008. {USB_DEVICE(0x0c45, 0x6005), DVNM("Sweex Tas5110")},
  1009. {USB_DEVICE(0x0c45, 0x6007), DVNM("Sonix sn9c101 + Tas5110D")},
  1010. {USB_DEVICE(0x0c45, 0x6009), DVNM("spcaCam@120")},
  1011. {USB_DEVICE(0x0c45, 0x600d), DVNM("spcaCam@120")},
  1012. {USB_DEVICE(0x0c45, 0x6011), DVNM("MAX Webcam Microdia")},
  1013. {USB_DEVICE(0x0c45, 0x6019), DVNM("Generic Sonix OV7630")},
  1014. {USB_DEVICE(0x0c45, 0x6024), DVNM("Generic Sonix Tas5130c")},
  1015. {USB_DEVICE(0x0c45, 0x6025), DVNM("Xcam Shanga")},
  1016. {USB_DEVICE(0x0c45, 0x6028), DVNM("Sonix Btc Pc380")},
  1017. {USB_DEVICE(0x0c45, 0x6029), DVNM("spcaCam@150")},
  1018. {USB_DEVICE(0x0c45, 0x602c), DVNM("Generic Sonix OV7630")},
  1019. {USB_DEVICE(0x0c45, 0x602d), DVNM("LIC-200 LG")},
  1020. {USB_DEVICE(0x0c45, 0x602e), DVNM("Genius VideoCam Messenger")},
  1021. {USB_DEVICE(0x0c45, 0x60af), DVNM("Trust WB3100P")},
  1022. {USB_DEVICE(0x0c45, 0x60b0), DVNM("Genius VideoCam Look")},
  1023. #endif
  1024. {}
  1025. };
  1026. MODULE_DEVICE_TABLE(usb, device_table);
  1027. /* -- device connect -- */
  1028. static int sd_probe(struct usb_interface *intf,
  1029. const struct usb_device_id *id)
  1030. {
  1031. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1032. THIS_MODULE);
  1033. }
  1034. static struct usb_driver sd_driver = {
  1035. .name = MODULE_NAME,
  1036. .id_table = device_table,
  1037. .probe = sd_probe,
  1038. .disconnect = gspca_disconnect,
  1039. };
  1040. /* -- module insert / remove -- */
  1041. static int __init sd_mod_init(void)
  1042. {
  1043. if (usb_register(&sd_driver) < 0)
  1044. return -1;
  1045. PDEBUG(D_PROBE, "v%s registered", version);
  1046. return 0;
  1047. }
  1048. static void __exit sd_mod_exit(void)
  1049. {
  1050. usb_deregister(&sd_driver);
  1051. PDEBUG(D_PROBE, "deregistered");
  1052. }
  1053. module_init(sd_mod_init);
  1054. module_exit(sd_mod_exit);