spca506.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * SPCA506 chip based cameras function
  3. * M Xhaard 15/04/2004 based on different work Mark Taylor and others
  4. * and my own snoopy file on a pv-321c donate by a german compagny
  5. * "Firma Frank Gmbh" from Saarbruecken
  6. *
  7. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #define MODULE_NAME "spca506"
  24. #include "gspca.h"
  25. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  26. MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
  27. MODULE_LICENSE("GPL");
  28. /* specific webcam descriptor */
  29. struct sd {
  30. struct gspca_dev gspca_dev; /* !! must be the first item */
  31. char norme;
  32. char channel;
  33. };
  34. static const struct v4l2_pix_format vga_mode[] = {
  35. {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  36. .bytesperline = 160,
  37. .sizeimage = 160 * 120 * 3 / 2,
  38. .colorspace = V4L2_COLORSPACE_SRGB,
  39. .priv = 5},
  40. {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  41. .bytesperline = 176,
  42. .sizeimage = 176 * 144 * 3 / 2,
  43. .colorspace = V4L2_COLORSPACE_SRGB,
  44. .priv = 4},
  45. {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  46. .bytesperline = 320,
  47. .sizeimage = 320 * 240 * 3 / 2,
  48. .colorspace = V4L2_COLORSPACE_SRGB,
  49. .priv = 2},
  50. {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  51. .bytesperline = 352,
  52. .sizeimage = 352 * 288 * 3 / 2,
  53. .colorspace = V4L2_COLORSPACE_SRGB,
  54. .priv = 1},
  55. {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  56. .bytesperline = 640,
  57. .sizeimage = 640 * 480 * 3 / 2,
  58. .colorspace = V4L2_COLORSPACE_SRGB,
  59. .priv = 0},
  60. };
  61. #define SPCA50X_OFFSET_DATA 10
  62. #define SAA7113_bright 0x0a /* defaults 0x80 */
  63. #define SAA7113_contrast 0x0b /* defaults 0x47 */
  64. #define SAA7113_saturation 0x0c /* defaults 0x40 */
  65. #define SAA7113_hue 0x0d /* defaults 0x00 */
  66. #define SAA7113_I2C_BASE_WRITE 0x4a
  67. /* read 'len' bytes to gspca_dev->usb_buf */
  68. static void reg_r(struct gspca_dev *gspca_dev,
  69. __u16 req,
  70. __u16 index,
  71. __u16 length)
  72. {
  73. usb_control_msg(gspca_dev->dev,
  74. usb_rcvctrlpipe(gspca_dev->dev, 0),
  75. req,
  76. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  77. 0, /* value */
  78. index, gspca_dev->usb_buf, length,
  79. 500);
  80. }
  81. static void reg_w(struct usb_device *dev,
  82. __u16 req,
  83. __u16 value,
  84. __u16 index)
  85. {
  86. usb_control_msg(dev,
  87. usb_sndctrlpipe(dev, 0),
  88. req,
  89. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  90. value, index,
  91. NULL, 0, 500);
  92. }
  93. static void spca506_Initi2c(struct gspca_dev *gspca_dev)
  94. {
  95. reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
  96. }
  97. static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
  98. __u16 reg)
  99. {
  100. int retry = 60;
  101. reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
  102. reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
  103. while (retry--) {
  104. reg_r(gspca_dev, 0x07, 0x0003, 2);
  105. if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
  106. break;
  107. }
  108. }
  109. static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
  110. __u16 norme,
  111. __u16 channel)
  112. {
  113. struct sd *sd = (struct sd *) gspca_dev;
  114. /* fixme: check if channel == 0..3 and 6..9 (8 values) */
  115. __u8 setbit0 = 0x00;
  116. __u8 setbit1 = 0x00;
  117. __u8 videomask = 0x00;
  118. PDEBUG(D_STREAM, "** Open Set Norme **");
  119. spca506_Initi2c(gspca_dev);
  120. /* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
  121. /* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
  122. /* and exclude SAA7113 reserved channel set default 0 otherwise */
  123. if (norme & V4L2_STD_NTSC)
  124. setbit0 = 0x01;
  125. if (channel == 4 || channel == 5 || channel > 9)
  126. channel = 0;
  127. if (channel < 4)
  128. setbit1 = 0x02;
  129. videomask = (0x48 | setbit0 | setbit1);
  130. reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
  131. spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
  132. if (norme & V4L2_STD_NTSC)
  133. spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
  134. /* Chrominance Control NTSC N */
  135. else if (norme & V4L2_STD_SECAM)
  136. spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
  137. /* Chrominance Control SECAM */
  138. else
  139. spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
  140. /* Chrominance Control PAL BGHIV */
  141. sd->norme = norme;
  142. sd->channel = channel;
  143. PDEBUG(D_STREAM, "Set Video Byte to 0x%2x", videomask);
  144. PDEBUG(D_STREAM, "Set Norme: %08x Channel %d", norme, channel);
  145. }
  146. static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
  147. __u16 *norme, __u16 *channel)
  148. {
  149. struct sd *sd = (struct sd *) gspca_dev;
  150. /* Read the register is not so good value change so
  151. we use your own copy in spca50x struct */
  152. *norme = sd->norme;
  153. *channel = sd->channel;
  154. PDEBUG(D_STREAM, "Get Norme: %d Channel %d", *norme, *channel);
  155. }
  156. static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
  157. __u16 xmult, __u16 ymult)
  158. {
  159. struct usb_device *dev = gspca_dev->dev;
  160. PDEBUG(D_STREAM, "** SetSize **");
  161. reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
  162. /* Soft snap 0x40 Hard 0x41 */
  163. reg_w(dev, 0x04, 0x41, 0x0001);
  164. reg_w(dev, 0x04, 0x00, 0x0002);
  165. /* reserved */
  166. reg_w(dev, 0x04, 0x00, 0x0003);
  167. /* reserved */
  168. reg_w(dev, 0x04, 0x00, 0x0004);
  169. /* reserved */
  170. reg_w(dev, 0x04, 0x01, 0x0005);
  171. /* reserced */
  172. reg_w(dev, 0x04, xmult, 0x0006);
  173. /* reserved */
  174. reg_w(dev, 0x04, ymult, 0x0007);
  175. /* compression 1 */
  176. reg_w(dev, 0x04, 0x00, 0x0008);
  177. /* T=64 -> 2 */
  178. reg_w(dev, 0x04, 0x00, 0x0009);
  179. /* threshold2D */
  180. reg_w(dev, 0x04, 0x21, 0x000a);
  181. /* quantization */
  182. reg_w(dev, 0x04, 0x00, 0x000b);
  183. }
  184. /* this function is called at probe time */
  185. static int sd_config(struct gspca_dev *gspca_dev,
  186. const struct usb_device_id *id)
  187. {
  188. struct cam *cam;
  189. cam = &gspca_dev->cam;
  190. cam->cam_mode = vga_mode;
  191. cam->nmodes = ARRAY_SIZE(vga_mode);
  192. return 0;
  193. }
  194. /* this function is called at probe and resume time */
  195. static int sd_init(struct gspca_dev *gspca_dev)
  196. {
  197. struct usb_device *dev = gspca_dev->dev;
  198. reg_w(dev, 0x03, 0x00, 0x0004);
  199. reg_w(dev, 0x03, 0xFF, 0x0003);
  200. reg_w(dev, 0x03, 0x00, 0x0000);
  201. reg_w(dev, 0x03, 0x1c, 0x0001);
  202. reg_w(dev, 0x03, 0x18, 0x0001);
  203. /* Init on PAL and composite input0 */
  204. spca506_SetNormeInput(gspca_dev, 0, 0);
  205. reg_w(dev, 0x03, 0x1c, 0x0001);
  206. reg_w(dev, 0x03, 0x18, 0x0001);
  207. reg_w(dev, 0x05, 0x00, 0x0000);
  208. reg_w(dev, 0x05, 0xef, 0x0001);
  209. reg_w(dev, 0x05, 0x00, 0x00c1);
  210. reg_w(dev, 0x05, 0x00, 0x00c2);
  211. reg_w(dev, 0x06, 0x18, 0x0002);
  212. reg_w(dev, 0x06, 0xf5, 0x0011);
  213. reg_w(dev, 0x06, 0x02, 0x0012);
  214. reg_w(dev, 0x06, 0xfb, 0x0013);
  215. reg_w(dev, 0x06, 0x00, 0x0014);
  216. reg_w(dev, 0x06, 0xa4, 0x0051);
  217. reg_w(dev, 0x06, 0x40, 0x0052);
  218. reg_w(dev, 0x06, 0x71, 0x0053);
  219. reg_w(dev, 0x06, 0x40, 0x0054);
  220. /************************************************/
  221. reg_w(dev, 0x03, 0x00, 0x0004);
  222. reg_w(dev, 0x03, 0x00, 0x0003);
  223. reg_w(dev, 0x03, 0x00, 0x0004);
  224. reg_w(dev, 0x03, 0xFF, 0x0003);
  225. reg_w(dev, 0x02, 0x00, 0x0000);
  226. reg_w(dev, 0x03, 0x60, 0x0000);
  227. reg_w(dev, 0x03, 0x18, 0x0001);
  228. /* for a better reading mx :) */
  229. /*sdca506_WriteI2c(value,register) */
  230. spca506_Initi2c(gspca_dev);
  231. spca506_WriteI2c(gspca_dev, 0x08, 0x01);
  232. spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
  233. /* input composite video */
  234. spca506_WriteI2c(gspca_dev, 0x33, 0x03);
  235. spca506_WriteI2c(gspca_dev, 0x00, 0x04);
  236. spca506_WriteI2c(gspca_dev, 0x00, 0x05);
  237. spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
  238. spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
  239. spca506_WriteI2c(gspca_dev, 0x98, 0x08);
  240. spca506_WriteI2c(gspca_dev, 0x03, 0x09);
  241. spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
  242. spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
  243. spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
  244. spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
  245. spca506_WriteI2c(gspca_dev, 0x03, 0x0e); /* Chroma Pal adjust */
  246. spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
  247. spca506_WriteI2c(gspca_dev, 0x00, 0x10);
  248. spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
  249. spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
  250. spca506_WriteI2c(gspca_dev, 0x01, 0x13);
  251. spca506_WriteI2c(gspca_dev, 0x00, 0x14);
  252. spca506_WriteI2c(gspca_dev, 0x00, 0x15);
  253. spca506_WriteI2c(gspca_dev, 0x00, 0x16);
  254. spca506_WriteI2c(gspca_dev, 0x00, 0x17);
  255. spca506_WriteI2c(gspca_dev, 0x00, 0x18);
  256. spca506_WriteI2c(gspca_dev, 0x00, 0x19);
  257. spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
  258. spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
  259. spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
  260. spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
  261. spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
  262. spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
  263. spca506_WriteI2c(gspca_dev, 0x02, 0x40);
  264. spca506_WriteI2c(gspca_dev, 0xff, 0x41);
  265. spca506_WriteI2c(gspca_dev, 0xff, 0x42);
  266. spca506_WriteI2c(gspca_dev, 0xff, 0x43);
  267. spca506_WriteI2c(gspca_dev, 0xff, 0x44);
  268. spca506_WriteI2c(gspca_dev, 0xff, 0x45);
  269. spca506_WriteI2c(gspca_dev, 0xff, 0x46);
  270. spca506_WriteI2c(gspca_dev, 0xff, 0x47);
  271. spca506_WriteI2c(gspca_dev, 0xff, 0x48);
  272. spca506_WriteI2c(gspca_dev, 0xff, 0x49);
  273. spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
  274. spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
  275. spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
  276. spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
  277. spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
  278. spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
  279. spca506_WriteI2c(gspca_dev, 0xff, 0x50);
  280. spca506_WriteI2c(gspca_dev, 0xff, 0x51);
  281. spca506_WriteI2c(gspca_dev, 0xff, 0x52);
  282. spca506_WriteI2c(gspca_dev, 0xff, 0x53);
  283. spca506_WriteI2c(gspca_dev, 0xff, 0x54);
  284. spca506_WriteI2c(gspca_dev, 0xff, 0x55);
  285. spca506_WriteI2c(gspca_dev, 0xff, 0x56);
  286. spca506_WriteI2c(gspca_dev, 0xff, 0x57);
  287. spca506_WriteI2c(gspca_dev, 0x00, 0x58);
  288. spca506_WriteI2c(gspca_dev, 0x54, 0x59);
  289. spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
  290. spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
  291. spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
  292. spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
  293. spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
  294. spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
  295. spca506_WriteI2c(gspca_dev, 0x00, 0x60);
  296. spca506_WriteI2c(gspca_dev, 0x05, 0x61);
  297. spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
  298. PDEBUG(D_STREAM, "** Close Init *");
  299. return 0;
  300. }
  301. static int sd_start(struct gspca_dev *gspca_dev)
  302. {
  303. struct usb_device *dev = gspca_dev->dev;
  304. __u16 norme;
  305. __u16 channel;
  306. /**************************************/
  307. reg_w(dev, 0x03, 0x00, 0x0004);
  308. reg_w(dev, 0x03, 0x00, 0x0003);
  309. reg_w(dev, 0x03, 0x00, 0x0004);
  310. reg_w(dev, 0x03, 0xFF, 0x0003);
  311. reg_w(dev, 0x02, 0x00, 0x0000);
  312. reg_w(dev, 0x03, 0x60, 0x0000);
  313. reg_w(dev, 0x03, 0x18, 0x0001);
  314. /*sdca506_WriteI2c(value,register) */
  315. spca506_Initi2c(gspca_dev);
  316. spca506_WriteI2c(gspca_dev, 0x08, 0x01); /* Increment Delay */
  317. /* spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
  318. spca506_WriteI2c(gspca_dev, 0x33, 0x03);
  319. /* Analog Input Control 2 */
  320. spca506_WriteI2c(gspca_dev, 0x00, 0x04);
  321. /* Analog Input Control 3 */
  322. spca506_WriteI2c(gspca_dev, 0x00, 0x05);
  323. /* Analog Input Control 4 */
  324. spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
  325. /* Horizontal Sync Start 0xe9-0x0d */
  326. spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
  327. /* Horizontal Sync Stop 0x0d-0xf0 */
  328. spca506_WriteI2c(gspca_dev, 0x98, 0x08); /* Sync Control */
  329. /* Defaults value */
  330. spca506_WriteI2c(gspca_dev, 0x03, 0x09); /* Luminance Control */
  331. spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
  332. /* Luminance Brightness */
  333. spca506_WriteI2c(gspca_dev, 0x47, 0x0b); /* Luminance Contrast */
  334. spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
  335. /* Chrominance Saturation */
  336. spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
  337. /* Chrominance Hue Control */
  338. spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
  339. /* Chrominance Gain Control */
  340. /**************************************/
  341. spca506_WriteI2c(gspca_dev, 0x00, 0x10);
  342. /* Format/Delay Control */
  343. spca506_WriteI2c(gspca_dev, 0x0c, 0x11); /* Output Control 1 */
  344. spca506_WriteI2c(gspca_dev, 0xb8, 0x12); /* Output Control 2 */
  345. spca506_WriteI2c(gspca_dev, 0x01, 0x13); /* Output Control 3 */
  346. spca506_WriteI2c(gspca_dev, 0x00, 0x14); /* reserved */
  347. spca506_WriteI2c(gspca_dev, 0x00, 0x15); /* VGATE START */
  348. spca506_WriteI2c(gspca_dev, 0x00, 0x16); /* VGATE STOP */
  349. spca506_WriteI2c(gspca_dev, 0x00, 0x17); /* VGATE Control (MSB) */
  350. spca506_WriteI2c(gspca_dev, 0x00, 0x18);
  351. spca506_WriteI2c(gspca_dev, 0x00, 0x19);
  352. spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
  353. spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
  354. spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
  355. spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
  356. spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
  357. spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
  358. spca506_WriteI2c(gspca_dev, 0x02, 0x40);
  359. spca506_WriteI2c(gspca_dev, 0xff, 0x41);
  360. spca506_WriteI2c(gspca_dev, 0xff, 0x42);
  361. spca506_WriteI2c(gspca_dev, 0xff, 0x43);
  362. spca506_WriteI2c(gspca_dev, 0xff, 0x44);
  363. spca506_WriteI2c(gspca_dev, 0xff, 0x45);
  364. spca506_WriteI2c(gspca_dev, 0xff, 0x46);
  365. spca506_WriteI2c(gspca_dev, 0xff, 0x47);
  366. spca506_WriteI2c(gspca_dev, 0xff, 0x48);
  367. spca506_WriteI2c(gspca_dev, 0xff, 0x49);
  368. spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
  369. spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
  370. spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
  371. spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
  372. spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
  373. spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
  374. spca506_WriteI2c(gspca_dev, 0xff, 0x50);
  375. spca506_WriteI2c(gspca_dev, 0xff, 0x51);
  376. spca506_WriteI2c(gspca_dev, 0xff, 0x52);
  377. spca506_WriteI2c(gspca_dev, 0xff, 0x53);
  378. spca506_WriteI2c(gspca_dev, 0xff, 0x54);
  379. spca506_WriteI2c(gspca_dev, 0xff, 0x55);
  380. spca506_WriteI2c(gspca_dev, 0xff, 0x56);
  381. spca506_WriteI2c(gspca_dev, 0xff, 0x57);
  382. spca506_WriteI2c(gspca_dev, 0x00, 0x58);
  383. spca506_WriteI2c(gspca_dev, 0x54, 0x59);
  384. spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
  385. spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
  386. spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
  387. spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
  388. spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
  389. spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
  390. spca506_WriteI2c(gspca_dev, 0x00, 0x60);
  391. spca506_WriteI2c(gspca_dev, 0x05, 0x61);
  392. spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
  393. /**************************************/
  394. reg_w(dev, 0x05, 0x00, 0x0003);
  395. reg_w(dev, 0x05, 0x00, 0x0004);
  396. reg_w(dev, 0x03, 0x10, 0x0001);
  397. reg_w(dev, 0x03, 0x78, 0x0000);
  398. switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
  399. case 0:
  400. spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
  401. break;
  402. case 1:
  403. spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
  404. break;
  405. case 2:
  406. spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
  407. break;
  408. case 4:
  409. spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
  410. break;
  411. default:
  412. /* case 5: */
  413. spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
  414. break;
  415. }
  416. /* compress setting and size */
  417. /* set i2c luma */
  418. reg_w(dev, 0x02, 0x01, 0x0000);
  419. reg_w(dev, 0x03, 0x12, 0x0000);
  420. reg_r(gspca_dev, 0x04, 0x0001, 2);
  421. PDEBUG(D_STREAM, "webcam started");
  422. spca506_GetNormeInput(gspca_dev, &norme, &channel);
  423. spca506_SetNormeInput(gspca_dev, norme, channel);
  424. return 0;
  425. }
  426. static void sd_stopN(struct gspca_dev *gspca_dev)
  427. {
  428. struct usb_device *dev = gspca_dev->dev;
  429. reg_w(dev, 0x02, 0x00, 0x0000);
  430. reg_w(dev, 0x03, 0x00, 0x0004);
  431. reg_w(dev, 0x03, 0x00, 0x0003);
  432. }
  433. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  434. u8 *data, /* isoc packet */
  435. int len) /* iso packet length */
  436. {
  437. switch (data[0]) {
  438. case 0: /* start of frame */
  439. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  440. data += SPCA50X_OFFSET_DATA;
  441. len -= SPCA50X_OFFSET_DATA;
  442. gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
  443. break;
  444. case 0xff: /* drop */
  445. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  446. break;
  447. default:
  448. data += 1;
  449. len -= 1;
  450. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  451. break;
  452. }
  453. }
  454. static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
  455. {
  456. spca506_Initi2c(gspca_dev);
  457. spca506_WriteI2c(gspca_dev, val, SAA7113_bright);
  458. spca506_WriteI2c(gspca_dev, 0x01, 0x09);
  459. }
  460. static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
  461. {
  462. spca506_Initi2c(gspca_dev);
  463. spca506_WriteI2c(gspca_dev, val, SAA7113_contrast);
  464. spca506_WriteI2c(gspca_dev, 0x01, 0x09);
  465. }
  466. static void setcolors(struct gspca_dev *gspca_dev, s32 val)
  467. {
  468. spca506_Initi2c(gspca_dev);
  469. spca506_WriteI2c(gspca_dev, val, SAA7113_saturation);
  470. spca506_WriteI2c(gspca_dev, 0x01, 0x09);
  471. }
  472. static void sethue(struct gspca_dev *gspca_dev, s32 val)
  473. {
  474. spca506_Initi2c(gspca_dev);
  475. spca506_WriteI2c(gspca_dev, val, SAA7113_hue);
  476. spca506_WriteI2c(gspca_dev, 0x01, 0x09);
  477. }
  478. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  479. {
  480. struct gspca_dev *gspca_dev =
  481. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  482. gspca_dev->usb_err = 0;
  483. if (!gspca_dev->streaming)
  484. return 0;
  485. switch (ctrl->id) {
  486. case V4L2_CID_BRIGHTNESS:
  487. setbrightness(gspca_dev, ctrl->val);
  488. break;
  489. case V4L2_CID_CONTRAST:
  490. setcontrast(gspca_dev, ctrl->val);
  491. break;
  492. case V4L2_CID_SATURATION:
  493. setcolors(gspca_dev, ctrl->val);
  494. break;
  495. case V4L2_CID_HUE:
  496. sethue(gspca_dev, ctrl->val);
  497. break;
  498. }
  499. return gspca_dev->usb_err;
  500. }
  501. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  502. .s_ctrl = sd_s_ctrl,
  503. };
  504. static int sd_init_controls(struct gspca_dev *gspca_dev)
  505. {
  506. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  507. gspca_dev->vdev.ctrl_handler = hdl;
  508. v4l2_ctrl_handler_init(hdl, 4);
  509. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  510. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  511. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  512. V4L2_CID_CONTRAST, 0, 255, 1, 0x47);
  513. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  514. V4L2_CID_SATURATION, 0, 255, 1, 0x40);
  515. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  516. V4L2_CID_HUE, 0, 255, 1, 0);
  517. if (hdl->error) {
  518. pr_err("Could not initialize controls\n");
  519. return hdl->error;
  520. }
  521. return 0;
  522. }
  523. /* sub-driver description */
  524. static const struct sd_desc sd_desc = {
  525. .name = MODULE_NAME,
  526. .config = sd_config,
  527. .init = sd_init,
  528. .init_controls = sd_init_controls,
  529. .start = sd_start,
  530. .stopN = sd_stopN,
  531. .pkt_scan = sd_pkt_scan,
  532. };
  533. /* -- module initialisation -- */
  534. static const struct usb_device_id device_table[] = {
  535. {USB_DEVICE(0x06e1, 0xa190)},
  536. /*fixme: may be IntelPCCameraPro BRIDGE_SPCA505
  537. {USB_DEVICE(0x0733, 0x0430)}, */
  538. {USB_DEVICE(0x0734, 0x043b)},
  539. {USB_DEVICE(0x99fa, 0x8988)},
  540. {}
  541. };
  542. MODULE_DEVICE_TABLE(usb, device_table);
  543. /* -- device connect -- */
  544. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  545. {
  546. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  547. THIS_MODULE);
  548. }
  549. static struct usb_driver sd_driver = {
  550. .name = MODULE_NAME,
  551. .id_table = device_table,
  552. .probe = sd_probe,
  553. .disconnect = gspca_disconnect,
  554. #ifdef CONFIG_PM
  555. .suspend = gspca_suspend,
  556. .resume = gspca_resume,
  557. .reset_resume = gspca_resume,
  558. #endif
  559. };
  560. module_usb_driver(sd_driver);