sonixb.c 31 KB

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