sonixb.c 25 KB

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