sonixb.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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, 0)
  25. static const char version[] = "2.1.0";
  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. usb_control_msg(dev,
  319. usb_sndctrlpipe(dev, 0),
  320. 0x08, /* request */
  321. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  322. value,
  323. 0, /* index */
  324. (__u8 *) buffer, len,
  325. 500);
  326. }
  327. static int i2c_w(struct usb_device *dev, const __u8 *buffer)
  328. {
  329. int retry = 60;
  330. __u8 ByteReceive;
  331. /* is i2c ready */
  332. reg_w(dev, 0x08, buffer, 8);
  333. while (retry--) {
  334. msleep(10);
  335. reg_r(dev, 0x08, &ByteReceive);
  336. if (ByteReceive == 4)
  337. return 0;
  338. }
  339. return -1;
  340. }
  341. static void i2c_w_vector(struct usb_device *dev,
  342. const __u8 buffer[][8], int len)
  343. {
  344. for (;;) {
  345. reg_w(dev, 0x08, *buffer, 8);
  346. len -= 8;
  347. if (len <= 0)
  348. break;
  349. buffer++;
  350. }
  351. }
  352. static void setbrightness(struct gspca_dev *gspca_dev)
  353. {
  354. struct sd *sd = (struct sd *) gspca_dev;
  355. __u8 value;
  356. switch (sd->sensor) {
  357. case SENSOR_OV6650: {
  358. __u8 i2cOV6650[] =
  359. {0xa0, 0x60, 0x06, 0x11, 0x99, 0x04, 0x94, 0x15};
  360. i2cOV6650[3] = sd->brightness;
  361. if (i2c_w(gspca_dev->dev, i2cOV6650) < 0)
  362. goto err;
  363. break;
  364. }
  365. case SENSOR_OV7630: {
  366. __u8 i2cOV[] =
  367. {0xa0, 0x21, 0x06, 0x36, 0xbd, 0x06, 0xf6, 0x16};
  368. /* change reg 0x06 */
  369. i2cOV[3] = sd->brightness;
  370. if (i2c_w(gspca_dev->dev, i2cOV) < 0)
  371. goto err;
  372. break;
  373. }
  374. case SENSOR_PAS106: {
  375. __u8 i2c1[] =
  376. {0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
  377. i2c1[3] = sd->brightness >> 3;
  378. i2c1[2] = 0x0e;
  379. if (i2c_w(gspca_dev->dev, i2c1) < 0)
  380. goto err;
  381. i2c1[3] = 0x01;
  382. i2c1[2] = 0x13;
  383. if (i2c_w(gspca_dev->dev, i2c1) < 0)
  384. goto err;
  385. break;
  386. }
  387. case SENSOR_PAS202: {
  388. /* __u8 i2cpexpo1[] =
  389. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x16}; */
  390. __u8 i2cpexpo[] =
  391. {0xb0, 0x40, 0x0e, 0x01, 0xab, 0x00, 0x63, 0x16};
  392. __u8 i2cp202[] =
  393. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15};
  394. static __u8 i2cpdoit[] =
  395. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16};
  396. /* change reg 0x10 */
  397. i2cpexpo[4] = 0xff - sd->brightness;
  398. /* if(i2c_w(gspca_dev->dev,i2cpexpo1) < 0)
  399. goto err; */
  400. /* if(i2c_w(gspca_dev->dev,i2cpdoit) < 0)
  401. goto err; */
  402. if (i2c_w(gspca_dev->dev, i2cpexpo) < 0)
  403. goto err;
  404. if (i2c_w(gspca_dev->dev, i2cpdoit) < 0)
  405. goto err;
  406. i2cp202[3] = sd->brightness >> 3;
  407. if (i2c_w(gspca_dev->dev, i2cp202) < 0)
  408. goto err;
  409. if (i2c_w(gspca_dev->dev, i2cpdoit) < 0)
  410. goto err;
  411. break;
  412. }
  413. case SENSOR_TAS5130CXX:
  414. case SENSOR_TAS5110: {
  415. __u8 i2c[] =
  416. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  417. value = 0xff - sd->brightness;
  418. i2c[4] = value;
  419. PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]);
  420. if (i2c_w(gspca_dev->dev, i2c) < 0)
  421. goto err;
  422. break;
  423. }
  424. }
  425. return;
  426. err:
  427. PDEBUG(D_ERR, "i2c error brightness");
  428. }
  429. static void setcontrast(struct gspca_dev *gspca_dev)
  430. {
  431. struct sd *sd = (struct sd *) gspca_dev;
  432. __u8 gain;
  433. __u8 rgb_value;
  434. gain = sd->contrast >> 4;
  435. /* red and blue gain */
  436. rgb_value = gain << 4 | gain;
  437. reg_w(gspca_dev->dev, 0x10, &rgb_value, 1);
  438. /* green gain */
  439. rgb_value = gain;
  440. reg_w(gspca_dev->dev, 0x11, &rgb_value, 1);
  441. }
  442. /* this function is called at probe time */
  443. static int sd_config(struct gspca_dev *gspca_dev,
  444. const struct usb_device_id *id)
  445. {
  446. struct sd *sd = (struct sd *) gspca_dev;
  447. struct cam *cam;
  448. /* __u16 vendor; */
  449. __u16 product;
  450. int sif = 0;
  451. /* vendor = id->idVendor; */
  452. product = id->idProduct;
  453. /* switch (vendor) { */
  454. /* case 0x0c45: * Sonix */
  455. switch (product) {
  456. case 0x6001: /* SN9C102 */
  457. case 0x6005: /* SN9C101 */
  458. case 0x6007: /* SN9C101 */
  459. sd->sensor = SENSOR_TAS5110;
  460. sif = 1;
  461. break;
  462. case 0x6009: /* SN9C101 */
  463. case 0x600d: /* SN9C101 */
  464. case 0x6029: /* SN9C101 */
  465. sd->sensor = SENSOR_PAS106;
  466. sif = 1;
  467. break;
  468. case 0x6011: /* SN9C101 - SN9C101G */
  469. sd->sensor = SENSOR_OV6650;
  470. sif = 1;
  471. break;
  472. case 0x6019: /* SN9C101 */
  473. case 0x602c: /* SN9C102 */
  474. case 0x602e: /* SN9C102 */
  475. sd->sensor = SENSOR_OV7630;
  476. break;
  477. case 0x60b0: /* SN9C103 */
  478. sd->sensor = SENSOR_OV7630_3;
  479. break;
  480. case 0x6024: /* SN9C102 */
  481. case 0x6025: /* SN9C102 */
  482. sd->sensor = SENSOR_TAS5130CXX;
  483. break;
  484. case 0x6028: /* SN9C102 */
  485. sd->sensor = SENSOR_PAS202;
  486. break;
  487. case 0x602d: /* SN9C102 */
  488. sd->sensor = SENSOR_HV7131R;
  489. break;
  490. case 0x60af: /* SN9C103 */
  491. sd->sensor = SENSOR_PAS202;
  492. break;
  493. }
  494. /* break; */
  495. /* } */
  496. cam = &gspca_dev->cam;
  497. cam->dev_name = (char *) id->driver_info;
  498. cam->epaddr = 0x01;
  499. if (!sif) {
  500. cam->cam_mode = vga_mode;
  501. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  502. } else {
  503. cam->cam_mode = sif_mode;
  504. cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
  505. }
  506. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  507. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  508. if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */
  509. reg_w(gspca_dev->dev, 0x01, probe_ov7630, sizeof probe_ov7630);
  510. return 0;
  511. }
  512. /* this function is called at open time */
  513. static int sd_open(struct gspca_dev *gspca_dev)
  514. {
  515. __u8 ByteReceive;
  516. reg_r(gspca_dev->dev, 0x00, &ByteReceive);
  517. if (ByteReceive != 0x10)
  518. return -ENODEV;
  519. return 0;
  520. }
  521. static void pas106_i2cinit(struct usb_device *dev)
  522. {
  523. int i;
  524. const __u8 *data;
  525. __u8 i2c1[] = { 0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 };
  526. i = ARRAY_SIZE(pas106_data);
  527. data = pas106_data[0];
  528. while (--i >= 0) {
  529. memcpy(&i2c1[2], data, 2);
  530. /* copy 2 bytes from the template */
  531. if (i2c_w(dev, i2c1) < 0)
  532. PDEBUG(D_ERR, "i2c error pas106");
  533. data += 2;
  534. }
  535. }
  536. /* -- start the camera -- */
  537. static void sd_start(struct gspca_dev *gspca_dev)
  538. {
  539. struct sd *sd = (struct sd *) gspca_dev;
  540. struct usb_device *dev = gspca_dev->dev;
  541. int mode, l;
  542. const __u8 *sn9c10x;
  543. __u8 reg01, reg17;
  544. __u8 reg17_19[3];
  545. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode;
  546. switch (sd->sensor) {
  547. case SENSOR_HV7131R:
  548. sn9c10x = initHv7131;
  549. reg17_19[0] = 0x60;
  550. reg17_19[1] = (mode << 4) | 0x8a;
  551. reg17_19[2] = 0x20;
  552. break;
  553. case SENSOR_OV6650:
  554. sn9c10x = initOv6650;
  555. reg17_19[0] = 0x68;
  556. reg17_19[1] = (mode << 4) | 0x8b;
  557. reg17_19[2] = 0x20;
  558. break;
  559. case SENSOR_OV7630:
  560. sn9c10x = initOv7630;
  561. reg17_19[0] = 0x68;
  562. reg17_19[1] = (mode << 4) | COMP2;
  563. reg17_19[2] = MCK_INIT1;
  564. break;
  565. case SENSOR_OV7630_3:
  566. sn9c10x = initOv7630_3;
  567. reg17_19[0] = 0x68;
  568. reg17_19[1] = (mode << 4) | COMP2;
  569. reg17_19[2] = MCK_INIT1;
  570. break;
  571. case SENSOR_PAS106:
  572. sn9c10x = initPas106;
  573. reg17_19[0] = 0x24; /* 0x28 */
  574. reg17_19[1] = (mode << 4) | COMP1;
  575. reg17_19[2] = MCK_INIT1;
  576. break;
  577. case SENSOR_PAS202:
  578. sn9c10x = initPas202;
  579. reg17_19[0] = mode ? 0x24 : 0x20;
  580. reg17_19[1] = (mode << 4) | 0x89;
  581. reg17_19[2] = 0x20;
  582. break;
  583. case SENSOR_TAS5110:
  584. sn9c10x = initTas5110;
  585. reg17_19[0] = 0x60;
  586. reg17_19[1] = (mode << 4) | 0x86;
  587. reg17_19[2] = 0x2b; /* 0xf3; */
  588. break;
  589. default:
  590. /* case SENSOR_TAS5130CXX: */
  591. sn9c10x = initTas5130;
  592. reg17_19[0] = 0x60;
  593. reg17_19[1] = (mode << 4) | COMP;
  594. reg17_19[2] = mode ? 0x23 : 0x43;
  595. break;
  596. }
  597. switch (sd->sensor) {
  598. case SENSOR_OV7630:
  599. reg01 = 0x06;
  600. reg17 = 0x29;
  601. l = 0x10;
  602. break;
  603. case SENSOR_OV7630_3:
  604. reg01 = 0x44;
  605. reg17 = 0x68;
  606. l = 0x10;
  607. break;
  608. default:
  609. reg01 = sn9c10x[0];
  610. reg17 = sn9c10x[0x17 - 1];
  611. l = 0x1f;
  612. break;
  613. }
  614. /* reg 0x01 bit 2 video transfert on */
  615. reg_w(dev, 0x01, &reg01, 1);
  616. /* reg 0x17 SensorClk enable inv Clk 0x60 */
  617. reg_w(dev, 0x17, &reg17, 1);
  618. /*fixme: for ov7630 102
  619. reg_w(dev, 0x01, {0x06, sn9c10x[1]}, 2); */
  620. /* Set the registers from the template */
  621. reg_w(dev, 0x01, sn9c10x, l);
  622. switch (sd->sensor) {
  623. case SENSOR_HV7131R:
  624. i2c_w_vector(dev, hv7131_sensor_init,
  625. sizeof hv7131_sensor_init);
  626. break;
  627. case SENSOR_OV6650:
  628. i2c_w_vector(dev, ov6650_sensor_init,
  629. sizeof ov6650_sensor_init);
  630. break;
  631. case SENSOR_OV7630:
  632. i2c_w_vector(dev, ov7630_sensor_init_com,
  633. sizeof ov7630_sensor_init_com);
  634. msleep(200);
  635. i2c_w_vector(dev, ov7630_sensor_init,
  636. sizeof ov7630_sensor_init);
  637. break;
  638. case SENSOR_OV7630_3:
  639. i2c_w_vector(dev, ov7630_sensor_init_com,
  640. sizeof ov7630_sensor_init_com);
  641. msleep(200);
  642. i2c_w_vector(dev, ov7630_sensor_init_3,
  643. sizeof ov7630_sensor_init_3);
  644. break;
  645. case SENSOR_PAS106:
  646. pas106_i2cinit(dev);
  647. break;
  648. case SENSOR_PAS202:
  649. i2c_w_vector(dev, pas202_sensor_init,
  650. sizeof pas202_sensor_init);
  651. break;
  652. case SENSOR_TAS5110:
  653. i2c_w_vector(dev, tas5110_sensor_init,
  654. sizeof tas5110_sensor_init);
  655. break;
  656. default:
  657. /* case SENSOR_TAS5130CXX: */
  658. i2c_w_vector(dev, tas5130_sensor_init,
  659. sizeof tas5130_sensor_init);
  660. break;
  661. }
  662. /* H_size V_size 0x28, 0x1e maybe 640x480 */
  663. reg_w(dev, 0x15, &sn9c10x[0x15 - 1], 2);
  664. /* compression register */
  665. reg_w(dev, 0x18, &reg17_19[1], 1);
  666. /* H_start */ /*fixme: not ov7630*/
  667. reg_w(dev, 0x12, &sn9c10x[0x12 - 1], 1);
  668. /* V_START */ /*fixme: not ov7630*/
  669. reg_w(dev, 0x13, &sn9c10x[0x13 - 1], 1);
  670. /* reset 0x17 SensorClk enable inv Clk 0x60 */
  671. /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
  672. reg_w(dev, 0x17, &reg17_19[0], 1);
  673. /*MCKSIZE ->3 */ /*fixme: not ov7630*/
  674. reg_w(dev, 0x19, &reg17_19[2], 1);
  675. /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
  676. reg_w(dev, 0x1c, &sn9c10x[0x1c - 1], 4);
  677. /* Enable video transfert */
  678. reg_w(dev, 0x01, &sn9c10x[0], 1);
  679. /* Compression */
  680. reg_w(dev, 0x18, &reg17_19[1], 2);
  681. msleep(20);
  682. setcontrast(gspca_dev);
  683. setbrightness(gspca_dev);
  684. }
  685. static void sd_stopN(struct gspca_dev *gspca_dev)
  686. {
  687. __u8 ByteSend = 0;
  688. ByteSend = 0x09; /* 0X00 */
  689. reg_w(gspca_dev->dev, 0x01, &ByteSend, 1);
  690. }
  691. static void sd_stop0(struct gspca_dev *gspca_dev)
  692. {
  693. }
  694. static void sd_close(struct gspca_dev *gspca_dev)
  695. {
  696. }
  697. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  698. struct gspca_frame *frame, /* target */
  699. unsigned char *data, /* isoc packet */
  700. int len) /* iso packet length */
  701. {
  702. int p;
  703. if (len > 6 && len < 24) {
  704. for (p = 0; p < len - 6; p++) {
  705. if (data[0 + p] == 0xff
  706. && data[1 + p] == 0xff
  707. && data[2 + p] == 0x00
  708. && data[3 + p] == 0xc4
  709. && data[4 + p] == 0xc4
  710. && data[5 + p] == 0x96) { /* start of frame */
  711. frame = gspca_frame_add(gspca_dev,
  712. LAST_PACKET,
  713. frame,
  714. data, 0);
  715. data += 12;
  716. len -= 12;
  717. gspca_frame_add(gspca_dev, FIRST_PACKET,
  718. frame, data, len);
  719. return;
  720. }
  721. }
  722. }
  723. gspca_frame_add(gspca_dev, INTER_PACKET,
  724. frame, data, len);
  725. }
  726. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  727. {
  728. struct sd *sd = (struct sd *) gspca_dev;
  729. sd->brightness = val;
  730. if (gspca_dev->streaming)
  731. setbrightness(gspca_dev);
  732. return 0;
  733. }
  734. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  735. {
  736. struct sd *sd = (struct sd *) gspca_dev;
  737. *val = sd->brightness;
  738. return 0;
  739. }
  740. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  741. {
  742. struct sd *sd = (struct sd *) gspca_dev;
  743. sd->contrast = val;
  744. if (gspca_dev->streaming)
  745. setcontrast(gspca_dev);
  746. return 0;
  747. }
  748. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  749. {
  750. struct sd *sd = (struct sd *) gspca_dev;
  751. *val = sd->contrast;
  752. return 0;
  753. }
  754. /* sub-driver description */
  755. static struct sd_desc sd_desc = {
  756. .name = MODULE_NAME,
  757. .ctrls = sd_ctrls,
  758. .nctrls = ARRAY_SIZE(sd_ctrls),
  759. .config = sd_config,
  760. .open = sd_open,
  761. .start = sd_start,
  762. .stopN = sd_stopN,
  763. .stop0 = sd_stop0,
  764. .close = sd_close,
  765. .pkt_scan = sd_pkt_scan,
  766. };
  767. /* -- module initialisation -- */
  768. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  769. static __devinitdata struct usb_device_id device_table[] = {
  770. {USB_DEVICE(0x0c45, 0x6001), DVNM("Genius VideoCAM NB")},
  771. {USB_DEVICE(0x0c45, 0x6005), DVNM("Sweex Tas5110")},
  772. {USB_DEVICE(0x0c45, 0x6007), DVNM("Sonix sn9c101 + Tas5110D")},
  773. {USB_DEVICE(0x0c45, 0x6009), DVNM("spcaCam@120")},
  774. {USB_DEVICE(0x0c45, 0x600d), DVNM("spcaCam@120")},
  775. {USB_DEVICE(0x0c45, 0x6011), DVNM("MAX Webcam Microdia")},
  776. {USB_DEVICE(0x0c45, 0x6019), DVNM("Generic Sonix OV7630")},
  777. {USB_DEVICE(0x0c45, 0x6024), DVNM("Generic Sonix Tas5130c")},
  778. {USB_DEVICE(0x0c45, 0x6025), DVNM("Xcam Shanga")},
  779. {USB_DEVICE(0x0c45, 0x6028), DVNM("Sonix Btc Pc380")},
  780. {USB_DEVICE(0x0c45, 0x6029), DVNM("spcaCam@150")},
  781. {USB_DEVICE(0x0c45, 0x602c), DVNM("Generic Sonix OV7630")},
  782. {USB_DEVICE(0x0c45, 0x602d), DVNM("LIC-200 LG")},
  783. {USB_DEVICE(0x0c45, 0x602e), DVNM("Genius VideoCam Messenger")},
  784. {USB_DEVICE(0x0c45, 0x60af), DVNM("Trust WB3100P")},
  785. {USB_DEVICE(0x0c45, 0x60b0), DVNM("Genius VideoCam Look")},
  786. {}
  787. };
  788. MODULE_DEVICE_TABLE(usb, device_table);
  789. /* -- device connect -- */
  790. static int sd_probe(struct usb_interface *intf,
  791. const struct usb_device_id *id)
  792. {
  793. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  794. THIS_MODULE);
  795. }
  796. static struct usb_driver sd_driver = {
  797. .name = MODULE_NAME,
  798. .id_table = device_table,
  799. .probe = sd_probe,
  800. .disconnect = gspca_disconnect,
  801. };
  802. /* -- module insert / remove -- */
  803. static int __init sd_mod_init(void)
  804. {
  805. if (usb_register(&sd_driver) < 0)
  806. return -1;
  807. PDEBUG(D_PROBE, "v%s registered", version);
  808. return 0;
  809. }
  810. static void __exit sd_mod_exit(void)
  811. {
  812. usb_deregister(&sd_driver);
  813. PDEBUG(D_PROBE, "deregistered");
  814. }
  815. module_init(sd_mod_init);
  816. module_exit(sd_mod_exit);