sonixb.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. unsigned char brightness;
  33. unsigned char contrast;
  34. unsigned char fr_h_sz; /* size of frame header */
  35. char sensor; /* Type of image sensor chip */
  36. #define SENSOR_HV7131R 0
  37. #define SENSOR_OV6650 1
  38. #define SENSOR_OV7630 2
  39. #define SENSOR_OV7630_3 3
  40. #define SENSOR_PAS106 4
  41. #define SENSOR_PAS202 5
  42. #define SENSOR_TAS5110 6
  43. #define SENSOR_TAS5130CXX 7
  44. };
  45. #define COMP2 0x8f
  46. #define COMP 0xc7 /* 0x87 //0x07 */
  47. #define COMP1 0xc9 /* 0x89 //0x09 */
  48. #define MCK_INIT 0x63
  49. #define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
  50. #define SYS_CLK 0x04
  51. /* V4L2 controls supported by the driver */
  52. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  53. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  54. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  55. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  56. static struct ctrl sd_ctrls[] = {
  57. #define SD_BRIGHTNESS 0
  58. {
  59. {
  60. .id = V4L2_CID_BRIGHTNESS,
  61. .type = V4L2_CTRL_TYPE_INTEGER,
  62. .name = "Brightness",
  63. .minimum = 0,
  64. .maximum = 255,
  65. .step = 1,
  66. .default_value = 127,
  67. },
  68. .set = sd_setbrightness,
  69. .get = sd_getbrightness,
  70. },
  71. #define SD_CONTRAST 1
  72. {
  73. {
  74. .id = V4L2_CID_CONTRAST,
  75. .type = V4L2_CTRL_TYPE_INTEGER,
  76. .name = "Contrast",
  77. .minimum = 0,
  78. .maximum = 255,
  79. .step = 1,
  80. .default_value = 127,
  81. },
  82. .set = sd_setcontrast,
  83. .get = sd_getcontrast,
  84. },
  85. };
  86. static struct v4l2_pix_format vga_mode[] = {
  87. {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  88. .bytesperline = 160,
  89. .sizeimage = 160 * 120,
  90. .colorspace = V4L2_COLORSPACE_SRGB,
  91. .priv = 2},
  92. {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  93. .bytesperline = 320,
  94. .sizeimage = 320 * 240,
  95. .colorspace = V4L2_COLORSPACE_SRGB,
  96. .priv = 1},
  97. {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  98. .bytesperline = 640,
  99. .sizeimage = 640 * 480,
  100. .colorspace = V4L2_COLORSPACE_SRGB,
  101. .priv = 0},
  102. };
  103. static struct v4l2_pix_format sif_mode[] = {
  104. {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  105. .bytesperline = 176,
  106. .sizeimage = 176 * 144,
  107. .colorspace = V4L2_COLORSPACE_SRGB,
  108. .priv = 1},
  109. {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  110. .bytesperline = 352,
  111. .sizeimage = 352 * 288,
  112. .colorspace = V4L2_COLORSPACE_SRGB,
  113. .priv = 0},
  114. };
  115. static const __u8 probe_ov7630[] = {0x08, 0x44};
  116. static const __u8 initHv7131[] = {
  117. 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
  118. 0x00, 0x00,
  119. 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* shift from 0x02 0x01 0x00 */
  120. 0x28, 0x1e, 0x60, 0x8a, 0x20,
  121. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c
  122. };
  123. static const __u8 hv7131_sensor_init[][8] = {
  124. {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
  125. {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
  126. {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
  127. {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
  128. {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
  129. };
  130. static const __u8 initOv6650[] = {
  131. 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  132. 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  133. 0x00, 0x02, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x0b,
  134. 0x10, 0x1d, 0x10, 0x00, 0x06, 0x1f, 0x00
  135. };
  136. static const __u8 ov6650_sensor_init[][8] =
  137. {
  138. /* Bright, contrast, etc are set througth SCBB interface.
  139. * AVCAP on win2 do not send any data on this controls. */
  140. /* Anyway, some registers appears to alter bright and constrat */
  141. {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  142. {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
  143. {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
  144. /* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},
  145. * THIS SET GREEN SCREEN
  146. * (pixels could be innverted in decode kind of "brg",
  147. * but blue wont be there. Avoid this data ... */
  148. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
  149. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
  150. {0xa0, 0x60, 0x30, 0x3d, 0x0A, 0xd8, 0xa4, 0x10},
  151. {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10},
  152. {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
  153. {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */
  154. {0xa0, 0x60, 0x10, 0x5d, 0x99, 0x04, 0x94, 0x16},
  155. {0xa0, 0x60, 0x2d, 0x0a, 0x99, 0x04, 0x94, 0x16},
  156. {0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16},
  157. {0xa0, 0x60, 0x33, 0x40, 0x99, 0x04, 0x94, 0x16},
  158. {0xa0, 0x60, 0x11, 0xc0, 0x99, 0x04, 0x94, 0x16},
  159. {0xa0, 0x60, 0x00, 0x16, 0x99, 0x04, 0x94, 0x15}, /* bright / Lumino */
  160. {0xa0, 0x60, 0x2b, 0xab, 0x99, 0x04, 0x94, 0x15},
  161. /* ?flicker o brillo */
  162. {0xa0, 0x60, 0x2d, 0x2a, 0x99, 0x04, 0x94, 0x15},
  163. {0xa0, 0x60, 0x2d, 0x2b, 0x99, 0x04, 0x94, 0x16},
  164. {0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16},
  165. {0xa0, 0x60, 0x33, 0x00, 0x99, 0x04, 0x94, 0x16},
  166. {0xa0, 0x60, 0x10, 0x57, 0x99, 0x04, 0x94, 0x16},
  167. {0xa0, 0x60, 0x2d, 0x2b, 0x99, 0x04, 0x94, 0x16},
  168. {0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16},
  169. /* Low Light (Enabled: 0x32 0x1 | Disabled: 0x32 0x00) */
  170. {0xa0, 0x60, 0x33, 0x29, 0x99, 0x04, 0x94, 0x16},
  171. /* Low Ligth (Enabled: 0x33 0x13 | Disabled: 0x33 0x29) */
  172. /* {0xa0, 0x60, 0x11, 0xc1, 0x99, 0x04, 0x94, 0x16}, */
  173. {0xa0, 0x60, 0x00, 0x17, 0x99, 0x04, 0x94, 0x15}, /* clip? r */
  174. {0xa0, 0x60, 0x00, 0x18, 0x99, 0x04, 0x94, 0x15}, /* clip? r */
  175. };
  176. static const __u8 initOv7630[] = {
  177. 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */
  178. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
  179. 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */
  180. 0x28, 0x1e, /* H & V sizes r15 .. r16 */
  181. 0x68, COMP1, MCK_INIT1, /* r17 .. r19 */
  182. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c /* r1a .. r1f */
  183. };
  184. static const __u8 initOv7630_3[] = {
  185. 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */
  186. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, /* r09 .. r10 */
  187. 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */
  188. 0x28, 0x1e, /* H & V sizes r15 .. r16 */
  189. 0x68, COMP1, MCK_INIT1, /* r17 .. r19 */
  190. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c /* r1a .. r1f */
  191. };
  192. static const __u8 ov7630_sensor_init_com[][8] = {
  193. {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  194. {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
  195. /* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
  196. {0xd0, 0x21, 0x12, 0x78, 0x00, 0x80, 0x34, 0x10}, /* jfm */
  197. {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
  198. {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
  199. {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
  200. {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
  201. {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
  202. {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
  203. {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
  204. /* {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10}, jfm */
  205. {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, /* jfm */
  206. {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
  207. {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
  208. {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
  209. {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
  210. {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
  211. {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
  212. };
  213. static const __u8 ov7630_sensor_init[][8] = {
  214. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 200ms */
  215. {0xa0, 0x21, 0x11, 0x01, 0xbd, 0x06, 0xf6, 0x10}, /* jfm */
  216. {0xa0, 0x21, 0x10, 0x57, 0xbd, 0x06, 0xf6, 0x16},
  217. {0xa0, 0x21, 0x76, 0x02, 0xbd, 0x06, 0xf6, 0x16},
  218. {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
  219. };
  220. static const __u8 ov7630_sensor_init_3[][8] = {
  221. {0xa0, 0x21, 0x10, 0x36, 0xbd, 0x06, 0xf6, 0x16}, /* exposure */
  222. {0xa0, 0x21, 0x76, 0x03, 0xbd, 0x06, 0xf6, 0x16},
  223. {0xa0, 0x21, 0x11, 0x01, 0xbd, 0x06, 0xf6, 0x16},
  224. {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
  225. /* {0xb0, 0x21, 0x2a, 0xc0, 0x3c, 0x06, 0xf6, 0x1d},
  226. * a0 1c,a0 1f,c0 3c frame rate ?line interval from ov6630 */
  227. /* {0xb0, 0x21, 0x2a, 0xa0, 0x1f, 0x06, 0xf6, 0x1d}, * from win */
  228. {0xb0, 0x21, 0x2a, 0xa0, 0x1c, 0x06, 0xf6, 0x1d},
  229. };
  230. static const __u8 initPas106[] = {
  231. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
  232. 0x00, 0x00,
  233. 0x00, 0x00, 0x00, 0x05, 0x01, 0x00,
  234. 0x16, 0x12, 0x28, COMP1, MCK_INIT1,
  235. 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
  236. };
  237. /* compression 0x86 mckinit1 0x2b */
  238. static const __u8 pas106_data[][2] = {
  239. {0x02, 0x04}, /* Pixel Clock Divider 6 */
  240. {0x03, 0x13}, /* Frame Time MSB */
  241. /* {0x03, 0x12}, * Frame Time MSB */
  242. {0x04, 0x06}, /* Frame Time LSB */
  243. /* {0x04, 0x05}, * Frame Time LSB */
  244. {0x05, 0x65}, /* Shutter Time Line Offset */
  245. /* {0x05, 0x6d}, * Shutter Time Line Offset */
  246. /* {0x06, 0xb1}, * Shutter Time Pixel Offset */
  247. {0x06, 0xcd}, /* Shutter Time Pixel Offset */
  248. {0x07, 0xc1}, /* Black Level Subtract Sign */
  249. /* {0x07, 0x00}, * Black Level Subtract Sign */
  250. {0x08, 0x06}, /* Black Level Subtract Level */
  251. {0x08, 0x06}, /* Black Level Subtract Level */
  252. /* {0x08, 0x01}, * Black Level Subtract Level */
  253. {0x09, 0x05}, /* Color Gain B Pixel 5 a */
  254. {0x0a, 0x04}, /* Color Gain G1 Pixel 1 5 */
  255. {0x0b, 0x04}, /* Color Gain G2 Pixel 1 0 5 */
  256. {0x0c, 0x05}, /* Color Gain R Pixel 3 1 */
  257. {0x0d, 0x00}, /* Color GainH Pixel */
  258. {0x0e, 0x0e}, /* Global Gain */
  259. {0x0f, 0x00}, /* Contrast */
  260. {0x10, 0x06}, /* H&V synchro polarity */
  261. {0x11, 0x06}, /* ?default */
  262. {0x12, 0x06}, /* DAC scale */
  263. {0x14, 0x02}, /* ?default */
  264. {0x13, 0x01}, /* Validate Settings */
  265. };
  266. static const __u8 initPas202[] = {
  267. 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
  268. 0x00, 0x00,
  269. 0x00, 0x00, 0x00, 0x07, 0x03, 0x0a, /* 6 */
  270. 0x28, 0x1e, 0x28, 0x89, 0x30,
  271. 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c
  272. };
  273. static const __u8 pas202_sensor_init[][8] = {
  274. {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10},
  275. {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
  276. {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
  277. {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x00, 0x32, 0x10},
  278. {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
  279. {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
  280. {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
  281. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  282. {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
  283. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  284. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x10},
  285. {0xb0, 0x40, 0x0e, 0x00, 0x3d, 0x00, 0x63, 0x10},
  286. {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
  287. {0xa0, 0x40, 0x10, 0x08, 0x3d, 0x00, 0x63, 0x15},
  288. {0xa0, 0x40, 0x02, 0x04, 0x3d, 0x00, 0x63, 0x16},
  289. {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
  290. {0xb0, 0x40, 0x0e, 0x00, 0x31, 0x00, 0x63, 0x16},
  291. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
  292. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15},
  293. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
  294. };
  295. static const __u8 initTas5110[] = {
  296. 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  297. 0x00, 0x00,
  298. 0x00, 0x01, 0x00, 0x46, 0x09, 0x0a, /* shift from 0x45 0x09 0x0a */
  299. 0x16, 0x12, 0x60, 0x86, 0x2b,
  300. 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
  301. };
  302. static const __u8 tas5110_sensor_init[][8] = {
  303. {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
  304. {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
  305. {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17},
  306. };
  307. static const __u8 initTas5130[] = {
  308. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  309. 0x00, 0x00,
  310. 0x00, 0x01, 0x00, 0x69, 0x0c, 0x0a,
  311. 0x28, 0x1e, 0x60, COMP, MCK_INIT,
  312. 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
  313. };
  314. static const __u8 tas5130_sensor_init[][8] = {
  315. /* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10},
  316. * shutter 0x47 short exposure? */
  317. {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
  318. /* shutter 0x01 long exposure */
  319. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
  320. };
  321. static void reg_r(struct usb_device *dev,
  322. __u16 value, __u8 *buffer)
  323. {
  324. usb_control_msg(dev,
  325. usb_rcvctrlpipe(dev, 0),
  326. 0, /* request */
  327. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  328. value,
  329. 0, /* index */
  330. buffer, 1,
  331. 500);
  332. }
  333. static void reg_w(struct usb_device *dev,
  334. __u16 value,
  335. const __u8 *buffer,
  336. int len)
  337. {
  338. __u8 tmpbuf[32];
  339. #ifdef CONFIG_VIDEO_ADV_DEBUG
  340. if (len > sizeof tmpbuf) {
  341. PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow");
  342. return;
  343. }
  344. #endif
  345. memcpy(tmpbuf, buffer, len);
  346. usb_control_msg(dev,
  347. usb_sndctrlpipe(dev, 0),
  348. 0x08, /* request */
  349. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  350. value,
  351. 0, /* index */
  352. tmpbuf, len,
  353. 500);
  354. }
  355. static int i2c_w(struct usb_device *dev, const __u8 *buffer)
  356. {
  357. int retry = 60;
  358. __u8 ByteReceive;
  359. /* is i2c ready */
  360. reg_w(dev, 0x08, buffer, 8);
  361. while (retry--) {
  362. msleep(10);
  363. reg_r(dev, 0x08, &ByteReceive);
  364. if (ByteReceive == 4)
  365. return 0;
  366. }
  367. return -1;
  368. }
  369. static void i2c_w_vector(struct usb_device *dev,
  370. const __u8 buffer[][8], int len)
  371. {
  372. for (;;) {
  373. reg_w(dev, 0x08, *buffer, 8);
  374. len -= 8;
  375. if (len <= 0)
  376. break;
  377. buffer++;
  378. }
  379. }
  380. static void setbrightness(struct gspca_dev *gspca_dev)
  381. {
  382. struct sd *sd = (struct sd *) gspca_dev;
  383. __u8 value;
  384. switch (sd->sensor) {
  385. case SENSOR_OV6650: {
  386. __u8 i2cOV6650[] =
  387. {0xa0, 0x60, 0x06, 0x11, 0x99, 0x04, 0x94, 0x15};
  388. i2cOV6650[3] = sd->brightness;
  389. if (i2c_w(gspca_dev->dev, i2cOV6650) < 0)
  390. goto err;
  391. break;
  392. }
  393. case SENSOR_OV7630: {
  394. __u8 i2cOV[] =
  395. {0xa0, 0x21, 0x06, 0x36, 0xbd, 0x06, 0xf6, 0x16};
  396. /* change reg 0x06 */
  397. i2cOV[3] = sd->brightness;
  398. if (i2c_w(gspca_dev->dev, i2cOV) < 0)
  399. goto err;
  400. break;
  401. }
  402. case SENSOR_PAS106: {
  403. __u8 i2c1[] =
  404. {0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
  405. i2c1[3] = sd->brightness >> 3;
  406. i2c1[2] = 0x0e;
  407. if (i2c_w(gspca_dev->dev, i2c1) < 0)
  408. goto err;
  409. i2c1[3] = 0x01;
  410. i2c1[2] = 0x13;
  411. if (i2c_w(gspca_dev->dev, i2c1) < 0)
  412. goto err;
  413. break;
  414. }
  415. case SENSOR_PAS202: {
  416. /* __u8 i2cpexpo1[] =
  417. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x16}; */
  418. __u8 i2cpexpo[] =
  419. {0xb0, 0x40, 0x0e, 0x01, 0xab, 0x00, 0x63, 0x16};
  420. __u8 i2cp202[] =
  421. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15};
  422. static __u8 i2cpdoit[] =
  423. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16};
  424. /* change reg 0x10 */
  425. i2cpexpo[4] = 0xff - sd->brightness;
  426. /* if(i2c_w(gspca_dev->dev,i2cpexpo1) < 0)
  427. goto err; */
  428. /* if(i2c_w(gspca_dev->dev,i2cpdoit) < 0)
  429. goto err; */
  430. if (i2c_w(gspca_dev->dev, i2cpexpo) < 0)
  431. goto err;
  432. if (i2c_w(gspca_dev->dev, i2cpdoit) < 0)
  433. goto err;
  434. i2cp202[3] = sd->brightness >> 3;
  435. if (i2c_w(gspca_dev->dev, i2cp202) < 0)
  436. goto err;
  437. if (i2c_w(gspca_dev->dev, i2cpdoit) < 0)
  438. goto err;
  439. break;
  440. }
  441. case SENSOR_TAS5130CXX:
  442. case SENSOR_TAS5110: {
  443. __u8 i2c[] =
  444. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  445. value = 0xff - sd->brightness;
  446. i2c[4] = value;
  447. PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]);
  448. if (i2c_w(gspca_dev->dev, i2c) < 0)
  449. goto err;
  450. break;
  451. }
  452. }
  453. return;
  454. err:
  455. PDEBUG(D_ERR, "i2c error brightness");
  456. }
  457. static void setcontrast(struct gspca_dev *gspca_dev)
  458. {
  459. struct sd *sd = (struct sd *) gspca_dev;
  460. __u8 gain;
  461. __u8 rgb_value;
  462. gain = sd->contrast >> 4;
  463. /* red and blue gain */
  464. rgb_value = gain << 4 | gain;
  465. reg_w(gspca_dev->dev, 0x10, &rgb_value, 1);
  466. /* green gain */
  467. rgb_value = gain;
  468. reg_w(gspca_dev->dev, 0x11, &rgb_value, 1);
  469. }
  470. /* this function is called at probe time */
  471. static int sd_config(struct gspca_dev *gspca_dev,
  472. const struct usb_device_id *id)
  473. {
  474. struct sd *sd = (struct sd *) gspca_dev;
  475. struct cam *cam;
  476. /* __u16 vendor; */
  477. __u16 product;
  478. int sif = 0;
  479. sd->fr_h_sz = 12; /* default size of the frame header */
  480. /* vendor = id->idVendor; */
  481. product = id->idProduct;
  482. /* switch (vendor) { */
  483. /* case 0x0c45: * Sonix */
  484. switch (product) {
  485. case 0x6001: /* SN9C102 */
  486. case 0x6005: /* SN9C101 */
  487. case 0x6007: /* SN9C101 */
  488. sd->sensor = SENSOR_TAS5110;
  489. sif = 1;
  490. break;
  491. case 0x6009: /* SN9C101 */
  492. case 0x600d: /* SN9C101 */
  493. case 0x6029: /* SN9C101 */
  494. sd->sensor = SENSOR_PAS106;
  495. sif = 1;
  496. break;
  497. case 0x6011: /* SN9C101 - SN9C101G */
  498. sd->sensor = SENSOR_OV6650;
  499. sif = 1;
  500. break;
  501. case 0x6019: /* SN9C101 */
  502. case 0x602c: /* SN9C102 */
  503. case 0x602e: /* SN9C102 */
  504. sd->sensor = SENSOR_OV7630;
  505. break;
  506. case 0x60b0: /* SN9C103 */
  507. sd->sensor = SENSOR_OV7630_3;
  508. sd->fr_h_sz = 18; /* size of frame header */
  509. break;
  510. case 0x6024: /* SN9C102 */
  511. case 0x6025: /* SN9C102 */
  512. sd->sensor = SENSOR_TAS5130CXX;
  513. break;
  514. case 0x6028: /* SN9C102 */
  515. sd->sensor = SENSOR_PAS202;
  516. break;
  517. case 0x602d: /* SN9C102 */
  518. sd->sensor = SENSOR_HV7131R;
  519. break;
  520. case 0x60af: /* SN9C103 */
  521. sd->sensor = SENSOR_PAS202;
  522. sd->fr_h_sz = 18; /* size of frame header (?) */
  523. break;
  524. }
  525. /* break; */
  526. /* } */
  527. cam = &gspca_dev->cam;
  528. cam->dev_name = (char *) id->driver_info;
  529. cam->epaddr = 0x01;
  530. if (!sif) {
  531. cam->cam_mode = vga_mode;
  532. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  533. } else {
  534. cam->cam_mode = sif_mode;
  535. cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
  536. }
  537. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  538. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  539. if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */
  540. reg_w(gspca_dev->dev, 0x01, probe_ov7630, sizeof probe_ov7630);
  541. return 0;
  542. }
  543. /* this function is called at open time */
  544. static int sd_open(struct gspca_dev *gspca_dev)
  545. {
  546. __u8 ByteReceive;
  547. reg_r(gspca_dev->dev, 0x00, &ByteReceive);
  548. if (ByteReceive != 0x10)
  549. return -ENODEV;
  550. return 0;
  551. }
  552. static void pas106_i2cinit(struct usb_device *dev)
  553. {
  554. int i;
  555. const __u8 *data;
  556. __u8 i2c1[] = { 0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 };
  557. i = ARRAY_SIZE(pas106_data);
  558. data = pas106_data[0];
  559. while (--i >= 0) {
  560. memcpy(&i2c1[2], data, 2);
  561. /* copy 2 bytes from the template */
  562. if (i2c_w(dev, i2c1) < 0)
  563. PDEBUG(D_ERR, "i2c error pas106");
  564. data += 2;
  565. }
  566. }
  567. /* -- start the camera -- */
  568. static void sd_start(struct gspca_dev *gspca_dev)
  569. {
  570. struct sd *sd = (struct sd *) gspca_dev;
  571. struct usb_device *dev = gspca_dev->dev;
  572. int mode, l;
  573. const __u8 *sn9c10x;
  574. __u8 reg01, reg17;
  575. __u8 reg17_19[3];
  576. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  577. switch (sd->sensor) {
  578. case SENSOR_HV7131R:
  579. sn9c10x = initHv7131;
  580. reg17_19[0] = 0x60;
  581. reg17_19[1] = (mode << 4) | 0x8a;
  582. reg17_19[2] = 0x20;
  583. break;
  584. case SENSOR_OV6650:
  585. sn9c10x = initOv6650;
  586. reg17_19[0] = 0x68;
  587. reg17_19[1] = (mode << 4) | 0x8b;
  588. reg17_19[2] = 0x20;
  589. break;
  590. case SENSOR_OV7630:
  591. sn9c10x = initOv7630;
  592. reg17_19[0] = 0x68;
  593. reg17_19[1] = (mode << 4) | COMP2;
  594. reg17_19[2] = MCK_INIT1;
  595. break;
  596. case SENSOR_OV7630_3:
  597. sn9c10x = initOv7630_3;
  598. reg17_19[0] = 0x68;
  599. reg17_19[1] = (mode << 4) | COMP2;
  600. reg17_19[2] = MCK_INIT1;
  601. break;
  602. case SENSOR_PAS106:
  603. sn9c10x = initPas106;
  604. reg17_19[0] = 0x24; /* 0x28 */
  605. reg17_19[1] = (mode << 4) | COMP1;
  606. reg17_19[2] = MCK_INIT1;
  607. break;
  608. case SENSOR_PAS202:
  609. sn9c10x = initPas202;
  610. reg17_19[0] = mode ? 0x24 : 0x20;
  611. reg17_19[1] = (mode << 4) | 0x89;
  612. reg17_19[2] = 0x20;
  613. break;
  614. case SENSOR_TAS5110:
  615. sn9c10x = initTas5110;
  616. reg17_19[0] = 0x60;
  617. reg17_19[1] = (mode << 4) | 0x86;
  618. reg17_19[2] = 0x2b; /* 0xf3; */
  619. break;
  620. default:
  621. /* case SENSOR_TAS5130CXX: */
  622. sn9c10x = initTas5130;
  623. reg17_19[0] = 0x60;
  624. reg17_19[1] = (mode << 4) | COMP;
  625. reg17_19[2] = mode ? 0x23 : 0x43;
  626. break;
  627. }
  628. switch (sd->sensor) {
  629. case SENSOR_OV7630:
  630. reg01 = 0x06;
  631. reg17 = 0x29;
  632. l = 0x10;
  633. break;
  634. case SENSOR_OV7630_3:
  635. reg01 = 0x44;
  636. reg17 = 0x68;
  637. l = 0x10;
  638. break;
  639. default:
  640. reg01 = sn9c10x[0];
  641. reg17 = sn9c10x[0x17 - 1];
  642. l = 0x1f;
  643. break;
  644. }
  645. /* reg 0x01 bit 2 video transfert on */
  646. reg_w(dev, 0x01, &reg01, 1);
  647. /* reg 0x17 SensorClk enable inv Clk 0x60 */
  648. reg_w(dev, 0x17, &reg17, 1);
  649. /*fixme: for ov7630 102
  650. reg_w(dev, 0x01, {0x06, sn9c10x[1]}, 2); */
  651. /* Set the registers from the template */
  652. reg_w(dev, 0x01, sn9c10x, l);
  653. switch (sd->sensor) {
  654. case SENSOR_HV7131R:
  655. i2c_w_vector(dev, hv7131_sensor_init,
  656. sizeof hv7131_sensor_init);
  657. break;
  658. case SENSOR_OV6650:
  659. i2c_w_vector(dev, ov6650_sensor_init,
  660. sizeof ov6650_sensor_init);
  661. break;
  662. case SENSOR_OV7630:
  663. i2c_w_vector(dev, ov7630_sensor_init_com,
  664. sizeof ov7630_sensor_init_com);
  665. msleep(200);
  666. i2c_w_vector(dev, ov7630_sensor_init,
  667. sizeof ov7630_sensor_init);
  668. break;
  669. case SENSOR_OV7630_3:
  670. i2c_w_vector(dev, ov7630_sensor_init_com,
  671. sizeof ov7630_sensor_init_com);
  672. msleep(200);
  673. i2c_w_vector(dev, ov7630_sensor_init_3,
  674. sizeof ov7630_sensor_init_3);
  675. break;
  676. case SENSOR_PAS106:
  677. pas106_i2cinit(dev);
  678. break;
  679. case SENSOR_PAS202:
  680. i2c_w_vector(dev, pas202_sensor_init,
  681. sizeof pas202_sensor_init);
  682. break;
  683. case SENSOR_TAS5110:
  684. i2c_w_vector(dev, tas5110_sensor_init,
  685. sizeof tas5110_sensor_init);
  686. break;
  687. default:
  688. /* case SENSOR_TAS5130CXX: */
  689. i2c_w_vector(dev, tas5130_sensor_init,
  690. sizeof tas5130_sensor_init);
  691. break;
  692. }
  693. /* H_size V_size 0x28, 0x1e maybe 640x480 */
  694. reg_w(dev, 0x15, &sn9c10x[0x15 - 1], 2);
  695. /* compression register */
  696. reg_w(dev, 0x18, &reg17_19[1], 1);
  697. /* H_start */ /*fixme: not ov7630*/
  698. reg_w(dev, 0x12, &sn9c10x[0x12 - 1], 1);
  699. /* V_START */ /*fixme: not ov7630*/
  700. reg_w(dev, 0x13, &sn9c10x[0x13 - 1], 1);
  701. /* reset 0x17 SensorClk enable inv Clk 0x60 */
  702. /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
  703. reg_w(dev, 0x17, &reg17_19[0], 1);
  704. /*MCKSIZE ->3 */ /*fixme: not ov7630*/
  705. reg_w(dev, 0x19, &reg17_19[2], 1);
  706. /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
  707. reg_w(dev, 0x1c, &sn9c10x[0x1c - 1], 4);
  708. /* Enable video transfert */
  709. reg_w(dev, 0x01, &sn9c10x[0], 1);
  710. /* Compression */
  711. reg_w(dev, 0x18, &reg17_19[1], 2);
  712. msleep(20);
  713. setcontrast(gspca_dev);
  714. setbrightness(gspca_dev);
  715. }
  716. static void sd_stopN(struct gspca_dev *gspca_dev)
  717. {
  718. __u8 ByteSend = 0;
  719. ByteSend = 0x09; /* 0X00 */
  720. reg_w(gspca_dev->dev, 0x01, &ByteSend, 1);
  721. }
  722. static void sd_stop0(struct gspca_dev *gspca_dev)
  723. {
  724. }
  725. static void sd_close(struct gspca_dev *gspca_dev)
  726. {
  727. }
  728. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  729. struct gspca_frame *frame, /* target */
  730. unsigned char *data, /* isoc packet */
  731. int len) /* iso packet length */
  732. {
  733. struct sd *sd;
  734. int i;
  735. if (len > 6 && len < 24) {
  736. for (i = 0; i < len - 6; i++) {
  737. if (data[0 + i] == 0xff
  738. && data[1 + i] == 0xff
  739. && data[2 + i] == 0x00
  740. && data[3 + i] == 0xc4
  741. && data[4 + i] == 0xc4
  742. && data[5 + i] == 0x96) { /* start of frame */
  743. frame = gspca_frame_add(gspca_dev, LAST_PACKET,
  744. frame, data, 0);
  745. sd = (struct sd *) gspca_dev;
  746. data += i + sd->fr_h_sz;
  747. len -= i + sd->fr_h_sz;
  748. gspca_frame_add(gspca_dev, FIRST_PACKET,
  749. frame, data, len);
  750. return;
  751. }
  752. }
  753. }
  754. gspca_frame_add(gspca_dev, INTER_PACKET,
  755. frame, data, len);
  756. }
  757. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  758. {
  759. struct sd *sd = (struct sd *) gspca_dev;
  760. sd->brightness = val;
  761. if (gspca_dev->streaming)
  762. setbrightness(gspca_dev);
  763. return 0;
  764. }
  765. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  766. {
  767. struct sd *sd = (struct sd *) gspca_dev;
  768. *val = sd->brightness;
  769. return 0;
  770. }
  771. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  772. {
  773. struct sd *sd = (struct sd *) gspca_dev;
  774. sd->contrast = val;
  775. if (gspca_dev->streaming)
  776. setcontrast(gspca_dev);
  777. return 0;
  778. }
  779. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  780. {
  781. struct sd *sd = (struct sd *) gspca_dev;
  782. *val = sd->contrast;
  783. return 0;
  784. }
  785. /* sub-driver description */
  786. static struct sd_desc sd_desc = {
  787. .name = MODULE_NAME,
  788. .ctrls = sd_ctrls,
  789. .nctrls = ARRAY_SIZE(sd_ctrls),
  790. .config = sd_config,
  791. .open = sd_open,
  792. .start = sd_start,
  793. .stopN = sd_stopN,
  794. .stop0 = sd_stop0,
  795. .close = sd_close,
  796. .pkt_scan = sd_pkt_scan,
  797. };
  798. /* -- module initialisation -- */
  799. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  800. static __devinitdata struct usb_device_id device_table[] = {
  801. {USB_DEVICE(0x0c45, 0x6001), DVNM("Genius VideoCAM NB")},
  802. {USB_DEVICE(0x0c45, 0x6005), DVNM("Sweex Tas5110")},
  803. {USB_DEVICE(0x0c45, 0x6007), DVNM("Sonix sn9c101 + Tas5110D")},
  804. {USB_DEVICE(0x0c45, 0x6009), DVNM("spcaCam@120")},
  805. {USB_DEVICE(0x0c45, 0x600d), DVNM("spcaCam@120")},
  806. {USB_DEVICE(0x0c45, 0x6011), DVNM("MAX Webcam Microdia")},
  807. {USB_DEVICE(0x0c45, 0x6019), DVNM("Generic Sonix OV7630")},
  808. {USB_DEVICE(0x0c45, 0x6024), DVNM("Generic Sonix Tas5130c")},
  809. {USB_DEVICE(0x0c45, 0x6025), DVNM("Xcam Shanga")},
  810. {USB_DEVICE(0x0c45, 0x6028), DVNM("Sonix Btc Pc380")},
  811. {USB_DEVICE(0x0c45, 0x6029), DVNM("spcaCam@150")},
  812. {USB_DEVICE(0x0c45, 0x602c), DVNM("Generic Sonix OV7630")},
  813. {USB_DEVICE(0x0c45, 0x602d), DVNM("LIC-200 LG")},
  814. {USB_DEVICE(0x0c45, 0x602e), DVNM("Genius VideoCam Messenger")},
  815. {USB_DEVICE(0x0c45, 0x60af), DVNM("Trust WB3100P")},
  816. {USB_DEVICE(0x0c45, 0x60b0), DVNM("Genius VideoCam Look")},
  817. {}
  818. };
  819. MODULE_DEVICE_TABLE(usb, device_table);
  820. /* -- device connect -- */
  821. static int sd_probe(struct usb_interface *intf,
  822. const struct usb_device_id *id)
  823. {
  824. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  825. THIS_MODULE);
  826. }
  827. static struct usb_driver sd_driver = {
  828. .name = MODULE_NAME,
  829. .id_table = device_table,
  830. .probe = sd_probe,
  831. .disconnect = gspca_disconnect,
  832. };
  833. /* -- module insert / remove -- */
  834. static int __init sd_mod_init(void)
  835. {
  836. if (usb_register(&sd_driver) < 0)
  837. return -1;
  838. PDEBUG(D_PROBE, "v%s registered", version);
  839. return 0;
  840. }
  841. static void __exit sd_mod_exit(void)
  842. {
  843. usb_deregister(&sd_driver);
  844. PDEBUG(D_PROBE, "deregistered");
  845. }
  846. module_init(sd_mod_init);
  847. module_exit(sd_mod_exit);