sn9c2028.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SN9C2028 library
  4. *
  5. * Copyright (C) 2009 Theodore Kilgore <[email protected]>
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #define MODULE_NAME "sn9c2028"
  9. #include "gspca.h"
  10. MODULE_AUTHOR("Theodore Kilgore");
  11. MODULE_DESCRIPTION("Sonix SN9C2028 USB Camera Driver");
  12. MODULE_LICENSE("GPL");
  13. /* specific webcam descriptor */
  14. struct sd {
  15. struct gspca_dev gspca_dev; /* !! must be the first item */
  16. u8 sof_read;
  17. u16 model;
  18. #define MIN_AVG_LUM 8500
  19. #define MAX_AVG_LUM 10000
  20. int avg_lum;
  21. u8 avg_lum_l;
  22. struct { /* autogain and gain control cluster */
  23. struct v4l2_ctrl *autogain;
  24. struct v4l2_ctrl *gain;
  25. };
  26. };
  27. struct init_command {
  28. unsigned char instruction[6];
  29. unsigned char to_read; /* length to read. 0 means no reply requested */
  30. };
  31. /* How to change the resolution of any of the VGA cams is unknown */
  32. static const struct v4l2_pix_format vga_mode[] = {
  33. {640, 480, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
  34. .bytesperline = 640,
  35. .sizeimage = 640 * 480 * 3 / 4,
  36. .colorspace = V4L2_COLORSPACE_SRGB,
  37. .priv = 0},
  38. };
  39. /* No way to change the resolution of the CIF cams is known */
  40. static const struct v4l2_pix_format cif_mode[] = {
  41. {352, 288, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
  42. .bytesperline = 352,
  43. .sizeimage = 352 * 288 * 3 / 4,
  44. .colorspace = V4L2_COLORSPACE_SRGB,
  45. .priv = 0},
  46. };
  47. /* the bytes to write are in gspca_dev->usb_buf */
  48. static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command)
  49. {
  50. int rc;
  51. gspca_dbg(gspca_dev, D_USBO, "sending command %02x%02x%02x%02x%02x%02x\n",
  52. command[0], command[1], command[2],
  53. command[3], command[4], command[5]);
  54. memcpy(gspca_dev->usb_buf, command, 6);
  55. rc = usb_control_msg(gspca_dev->dev,
  56. usb_sndctrlpipe(gspca_dev->dev, 0),
  57. USB_REQ_GET_CONFIGURATION,
  58. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  59. 2, 0, gspca_dev->usb_buf, 6, 500);
  60. if (rc < 0) {
  61. pr_err("command write [%02x] error %d\n",
  62. gspca_dev->usb_buf[0], rc);
  63. return rc;
  64. }
  65. return 0;
  66. }
  67. static int sn9c2028_read1(struct gspca_dev *gspca_dev)
  68. {
  69. int rc;
  70. rc = usb_control_msg(gspca_dev->dev,
  71. usb_rcvctrlpipe(gspca_dev->dev, 0),
  72. USB_REQ_GET_STATUS,
  73. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  74. 1, 0, gspca_dev->usb_buf, 1, 500);
  75. if (rc != 1) {
  76. pr_err("read1 error %d\n", rc);
  77. return (rc < 0) ? rc : -EIO;
  78. }
  79. gspca_dbg(gspca_dev, D_USBI, "read1 response %02x\n",
  80. gspca_dev->usb_buf[0]);
  81. return gspca_dev->usb_buf[0];
  82. }
  83. static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading)
  84. {
  85. int rc;
  86. rc = usb_control_msg(gspca_dev->dev,
  87. usb_rcvctrlpipe(gspca_dev->dev, 0),
  88. USB_REQ_GET_STATUS,
  89. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  90. 4, 0, gspca_dev->usb_buf, 4, 500);
  91. if (rc != 4) {
  92. pr_err("read4 error %d\n", rc);
  93. return (rc < 0) ? rc : -EIO;
  94. }
  95. memcpy(reading, gspca_dev->usb_buf, 4);
  96. gspca_dbg(gspca_dev, D_USBI, "read4 response %02x%02x%02x%02x\n",
  97. reading[0], reading[1], reading[2], reading[3]);
  98. return rc;
  99. }
  100. static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command)
  101. {
  102. int i, status;
  103. __u8 reading[4];
  104. status = sn9c2028_command(gspca_dev, command);
  105. if (status < 0)
  106. return status;
  107. status = -1;
  108. for (i = 0; i < 256 && status < 2; i++)
  109. status = sn9c2028_read1(gspca_dev);
  110. if (status < 0) {
  111. pr_err("long command status read error %d\n", status);
  112. return status;
  113. }
  114. memset(reading, 0, 4);
  115. status = sn9c2028_read4(gspca_dev, reading);
  116. if (status < 0)
  117. return status;
  118. /* in general, the first byte of the response is the first byte of
  119. * the command, or'ed with 8 */
  120. status = sn9c2028_read1(gspca_dev);
  121. if (status < 0)
  122. return status;
  123. return 0;
  124. }
  125. static int sn9c2028_short_command(struct gspca_dev *gspca_dev, u8 *command)
  126. {
  127. int err_code;
  128. err_code = sn9c2028_command(gspca_dev, command);
  129. if (err_code < 0)
  130. return err_code;
  131. err_code = sn9c2028_read1(gspca_dev);
  132. if (err_code < 0)
  133. return err_code;
  134. return 0;
  135. }
  136. /* this function is called at probe time */
  137. static int sd_config(struct gspca_dev *gspca_dev,
  138. const struct usb_device_id *id)
  139. {
  140. struct sd *sd = (struct sd *) gspca_dev;
  141. struct cam *cam = &gspca_dev->cam;
  142. gspca_dbg(gspca_dev, D_PROBE, "SN9C2028 camera detected (vid/pid 0x%04X:0x%04X)\n",
  143. id->idVendor, id->idProduct);
  144. sd->model = id->idProduct;
  145. switch (sd->model) {
  146. case 0x7005:
  147. gspca_dbg(gspca_dev, D_PROBE, "Genius Smart 300 camera\n");
  148. break;
  149. case 0x7003:
  150. gspca_dbg(gspca_dev, D_PROBE, "Genius Videocam Live v2\n");
  151. break;
  152. case 0x8000:
  153. gspca_dbg(gspca_dev, D_PROBE, "DC31VC\n");
  154. break;
  155. case 0x8001:
  156. gspca_dbg(gspca_dev, D_PROBE, "Spy camera\n");
  157. break;
  158. case 0x8003:
  159. gspca_dbg(gspca_dev, D_PROBE, "CIF camera\n");
  160. break;
  161. case 0x8008:
  162. gspca_dbg(gspca_dev, D_PROBE, "Mini-Shotz ms-350 camera\n");
  163. break;
  164. case 0x800a:
  165. gspca_dbg(gspca_dev, D_PROBE, "Vivitar 3350b type camera\n");
  166. cam->input_flags = V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  167. break;
  168. }
  169. switch (sd->model) {
  170. case 0x8000:
  171. case 0x8001:
  172. case 0x8003:
  173. cam->cam_mode = cif_mode;
  174. cam->nmodes = ARRAY_SIZE(cif_mode);
  175. break;
  176. default:
  177. cam->cam_mode = vga_mode;
  178. cam->nmodes = ARRAY_SIZE(vga_mode);
  179. }
  180. return 0;
  181. }
  182. /* this function is called at probe and resume time */
  183. static int sd_init(struct gspca_dev *gspca_dev)
  184. {
  185. int status;
  186. sn9c2028_read1(gspca_dev);
  187. sn9c2028_read1(gspca_dev);
  188. status = sn9c2028_read1(gspca_dev);
  189. return (status < 0) ? status : 0;
  190. }
  191. static int run_start_commands(struct gspca_dev *gspca_dev,
  192. struct init_command *cam_commands, int n)
  193. {
  194. int i, err_code = -1;
  195. for (i = 0; i < n; i++) {
  196. switch (cam_commands[i].to_read) {
  197. case 4:
  198. err_code = sn9c2028_long_command(gspca_dev,
  199. cam_commands[i].instruction);
  200. break;
  201. case 1:
  202. err_code = sn9c2028_short_command(gspca_dev,
  203. cam_commands[i].instruction);
  204. break;
  205. case 0:
  206. err_code = sn9c2028_command(gspca_dev,
  207. cam_commands[i].instruction);
  208. break;
  209. }
  210. if (err_code < 0)
  211. return err_code;
  212. }
  213. return 0;
  214. }
  215. static void set_gain(struct gspca_dev *gspca_dev, s32 g)
  216. {
  217. struct sd *sd = (struct sd *) gspca_dev;
  218. struct init_command genius_vcam_live_gain_cmds[] = {
  219. {{0x1d, 0x25, 0x10 /* This byte is gain */,
  220. 0x20, 0xab, 0x00}, 0},
  221. };
  222. if (!gspca_dev->streaming)
  223. return;
  224. switch (sd->model) {
  225. case 0x7003:
  226. genius_vcam_live_gain_cmds[0].instruction[2] = g;
  227. run_start_commands(gspca_dev, genius_vcam_live_gain_cmds,
  228. ARRAY_SIZE(genius_vcam_live_gain_cmds));
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  235. {
  236. struct gspca_dev *gspca_dev =
  237. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  238. struct sd *sd = (struct sd *)gspca_dev;
  239. gspca_dev->usb_err = 0;
  240. if (!gspca_dev->streaming)
  241. return 0;
  242. switch (ctrl->id) {
  243. /* standalone gain control */
  244. case V4L2_CID_GAIN:
  245. set_gain(gspca_dev, ctrl->val);
  246. break;
  247. /* autogain */
  248. case V4L2_CID_AUTOGAIN:
  249. set_gain(gspca_dev, sd->gain->val);
  250. break;
  251. }
  252. return gspca_dev->usb_err;
  253. }
  254. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  255. .s_ctrl = sd_s_ctrl,
  256. };
  257. static int sd_init_controls(struct gspca_dev *gspca_dev)
  258. {
  259. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  260. struct sd *sd = (struct sd *)gspca_dev;
  261. gspca_dev->vdev.ctrl_handler = hdl;
  262. v4l2_ctrl_handler_init(hdl, 2);
  263. switch (sd->model) {
  264. case 0x7003:
  265. sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  266. V4L2_CID_GAIN, 0, 20, 1, 0);
  267. sd->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  268. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  269. break;
  270. default:
  271. break;
  272. }
  273. return 0;
  274. }
  275. static int start_spy_cam(struct gspca_dev *gspca_dev)
  276. {
  277. struct init_command spy_start_commands[] = {
  278. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  279. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  280. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  281. {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
  282. {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
  283. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  284. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, /* width 352 */
  285. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, /* height 288 */
  286. /* {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, */
  287. {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4},
  288. {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* red gain ?*/
  289. /* {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, */
  290. {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
  291. /* {{0x13, 0x29, 0x01, 0x0c, 0x00, 0x00}, 4}, */
  292. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  293. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  294. /* {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, */
  295. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  296. {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
  297. /* {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, */
  298. {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
  299. {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
  300. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  301. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  302. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  303. {{0x11, 0x02, 0x06, 0x00, 0x00, 0x00}, 4},
  304. {{0x11, 0x03, 0x13, 0x00, 0x00, 0x00}, 4}, /*don't mess with*/
  305. /*{{0x11, 0x04, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
  306. {{0x11, 0x04, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
  307. /*{{0x11, 0x05, 0x65, 0x00, 0x00, 0x00}, 4}, observed */
  308. {{0x11, 0x05, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
  309. {{0x11, 0x06, 0xb1, 0x00, 0x00, 0x00}, 4}, /* observed */
  310. {{0x11, 0x07, 0x00, 0x00, 0x00, 0x00}, 4},
  311. /*{{0x11, 0x08, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
  312. {{0x11, 0x08, 0x0b, 0x00, 0x00, 0x00}, 4},
  313. {{0x11, 0x09, 0x01, 0x00, 0x00, 0x00}, 4},
  314. {{0x11, 0x0a, 0x01, 0x00, 0x00, 0x00}, 4},
  315. {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
  316. {{0x11, 0x0c, 0x01, 0x00, 0x00, 0x00}, 4},
  317. {{0x11, 0x0d, 0x00, 0x00, 0x00, 0x00}, 4},
  318. {{0x11, 0x0e, 0x04, 0x00, 0x00, 0x00}, 4},
  319. /* {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4}, */
  320. /* brightness or gain. 0 is default. 4 is good
  321. * indoors at night with incandescent lighting */
  322. {{0x11, 0x0f, 0x04, 0x00, 0x00, 0x00}, 4},
  323. {{0x11, 0x10, 0x06, 0x00, 0x00, 0x00}, 4}, /*hstart or hoffs*/
  324. {{0x11, 0x11, 0x06, 0x00, 0x00, 0x00}, 4},
  325. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  326. {{0x11, 0x14, 0x02, 0x00, 0x00, 0x00}, 4},
  327. {{0x11, 0x13, 0x01, 0x00, 0x00, 0x00}, 4},
  328. /* {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, observed */
  329. {{0x1b, 0x02, 0x11, 0x00, 0x00, 0x00}, 1}, /* brighter */
  330. /* {{0x1b, 0x13, 0x01, 0x00, 0x00, 0x00}, 1}, observed */
  331. {{0x1b, 0x13, 0x11, 0x00, 0x00, 0x00}, 1},
  332. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}, /* compresses */
  333. /* Camera should start to capture now. */
  334. };
  335. return run_start_commands(gspca_dev, spy_start_commands,
  336. ARRAY_SIZE(spy_start_commands));
  337. }
  338. static int start_cif_cam(struct gspca_dev *gspca_dev)
  339. {
  340. struct init_command cif_start_commands[] = {
  341. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  342. /* The entire sequence below seems redundant */
  343. /* {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  344. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  345. {{0x13, 0x22, 0x01, 0x06, 0x00, 0x00}, 4},
  346. {{0x13, 0x23, 0x01, 0x02, 0x00, 0x00}, 4},
  347. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  348. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, width?
  349. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, height?
  350. {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
  351. {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
  352. {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
  353. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  354. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  355. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  356. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  357. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  358. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  359. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  360. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  361. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},*/
  362. {{0x1b, 0x21, 0x00, 0x00, 0x00, 0x00}, 1},
  363. {{0x1b, 0x17, 0x00, 0x00, 0x00, 0x00}, 1},
  364. {{0x1b, 0x19, 0x00, 0x00, 0x00, 0x00}, 1},
  365. {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
  366. {{0x1b, 0x03, 0x5a, 0x00, 0x00, 0x00}, 1},
  367. {{0x1b, 0x04, 0x27, 0x00, 0x00, 0x00}, 1},
  368. {{0x1b, 0x05, 0x01, 0x00, 0x00, 0x00}, 1},
  369. {{0x1b, 0x12, 0x14, 0x00, 0x00, 0x00}, 1},
  370. {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
  371. {{0x1b, 0x14, 0x00, 0x00, 0x00, 0x00}, 1},
  372. {{0x1b, 0x15, 0x00, 0x00, 0x00, 0x00}, 1},
  373. {{0x1b, 0x16, 0x00, 0x00, 0x00, 0x00}, 1},
  374. {{0x1b, 0x77, 0xa2, 0x00, 0x00, 0x00}, 1},
  375. {{0x1b, 0x06, 0x0f, 0x00, 0x00, 0x00}, 1},
  376. {{0x1b, 0x07, 0x14, 0x00, 0x00, 0x00}, 1},
  377. {{0x1b, 0x08, 0x0f, 0x00, 0x00, 0x00}, 1},
  378. {{0x1b, 0x09, 0x10, 0x00, 0x00, 0x00}, 1},
  379. {{0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00}, 1},
  380. {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
  381. {{0x1b, 0x12, 0x07, 0x00, 0x00, 0x00}, 1},
  382. {{0x1b, 0x10, 0x1f, 0x00, 0x00, 0x00}, 1},
  383. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
  384. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 1}, /* width/8 */
  385. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 1}, /* height/8 */
  386. /* {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
  387. * {{0x13, 0x28, 0x01, 0x1e, 0x00, 0x00}, 4}, does nothing
  388. * {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, */
  389. /* {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
  390. * causes subsampling
  391. * but not a change in the resolution setting! */
  392. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  393. {{0x13, 0x2d, 0x01, 0x01, 0x00, 0x00}, 4},
  394. {{0x13, 0x2e, 0x01, 0x08, 0x00, 0x00}, 4},
  395. {{0x13, 0x2f, 0x01, 0x06, 0x00, 0x00}, 4},
  396. {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
  397. {{0x1b, 0x04, 0x6d, 0x00, 0x00, 0x00}, 1},
  398. {{0x1b, 0x05, 0x03, 0x00, 0x00, 0x00}, 1},
  399. {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
  400. {{0x1b, 0x0e, 0x01, 0x00, 0x00, 0x00}, 1},
  401. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
  402. {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
  403. {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
  404. {{0x1b, 0x10, 0x0f, 0x00, 0x00, 0x00}, 1},
  405. {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
  406. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
  407. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1},/* use compression */
  408. /* Camera should start to capture now. */
  409. };
  410. return run_start_commands(gspca_dev, cif_start_commands,
  411. ARRAY_SIZE(cif_start_commands));
  412. }
  413. static int start_ms350_cam(struct gspca_dev *gspca_dev)
  414. {
  415. struct init_command ms350_start_commands[] = {
  416. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  417. {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  418. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  419. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  420. {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
  421. {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
  422. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  423. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
  424. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
  425. {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
  426. {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4},
  427. {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
  428. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  429. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  430. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  431. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  432. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  433. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  434. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  435. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  436. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  437. {{0x11, 0x00, 0x01, 0x00, 0x00, 0x00}, 4},
  438. {{0x11, 0x01, 0x70, 0x00, 0x00, 0x00}, 4},
  439. {{0x11, 0x02, 0x05, 0x00, 0x00, 0x00}, 4},
  440. {{0x11, 0x03, 0x5d, 0x00, 0x00, 0x00}, 4},
  441. {{0x11, 0x04, 0x07, 0x00, 0x00, 0x00}, 4},
  442. {{0x11, 0x05, 0x25, 0x00, 0x00, 0x00}, 4},
  443. {{0x11, 0x06, 0x00, 0x00, 0x00, 0x00}, 4},
  444. {{0x11, 0x07, 0x09, 0x00, 0x00, 0x00}, 4},
  445. {{0x11, 0x08, 0x01, 0x00, 0x00, 0x00}, 4},
  446. {{0x11, 0x09, 0x00, 0x00, 0x00, 0x00}, 4},
  447. {{0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, 4},
  448. {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
  449. {{0x11, 0x0c, 0x00, 0x00, 0x00, 0x00}, 4},
  450. {{0x11, 0x0d, 0x0c, 0x00, 0x00, 0x00}, 4},
  451. {{0x11, 0x0e, 0x01, 0x00, 0x00, 0x00}, 4},
  452. {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4},
  453. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  454. {{0x11, 0x11, 0x00, 0x00, 0x00, 0x00}, 4},
  455. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  456. {{0x11, 0x13, 0x63, 0x00, 0x00, 0x00}, 4},
  457. {{0x11, 0x15, 0x70, 0x00, 0x00, 0x00}, 4},
  458. {{0x11, 0x18, 0x00, 0x00, 0x00, 0x00}, 4},
  459. {{0x11, 0x11, 0x01, 0x00, 0x00, 0x00}, 4},
  460. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* width */
  461. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* height */
  462. {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* vstart? */
  463. {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
  464. {{0x13, 0x29, 0x01, 0x40, 0x00, 0x00}, 4}, /* hstart? */
  465. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  466. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  467. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  468. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  469. {{0x1b, 0x02, 0x05, 0x00, 0x00, 0x00}, 1},
  470. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
  471. {{0x20, 0x18, 0x00, 0x00, 0x00, 0x00}, 1},
  472. {{0x1b, 0x02, 0x0a, 0x00, 0x00, 0x00}, 1},
  473. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 0},
  474. /* Camera should start to capture now. */
  475. };
  476. return run_start_commands(gspca_dev, ms350_start_commands,
  477. ARRAY_SIZE(ms350_start_commands));
  478. }
  479. static int start_genius_cam(struct gspca_dev *gspca_dev)
  480. {
  481. struct init_command genius_start_commands[] = {
  482. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  483. {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  484. {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
  485. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
  486. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
  487. /* "preliminary" width and height settings */
  488. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  489. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  490. {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
  491. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  492. {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
  493. {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
  494. {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
  495. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  496. {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
  497. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  498. {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
  499. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  500. {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
  501. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  502. {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
  503. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  504. {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
  505. {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
  506. {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
  507. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  508. {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
  509. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  510. {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
  511. {{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
  512. {{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
  513. {{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
  514. {{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
  515. {{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
  516. {{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
  517. {{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
  518. {{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
  519. {{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
  520. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* real width */
  521. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* real height */
  522. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  523. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  524. {{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
  525. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  526. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  527. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  528. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  529. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  530. {{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
  531. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  532. {{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
  533. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  534. {{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
  535. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  536. {{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
  537. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  538. {{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
  539. {{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
  540. {{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
  541. {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
  542. {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
  543. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0}
  544. /* Camera should start to capture now. */
  545. };
  546. return run_start_commands(gspca_dev, genius_start_commands,
  547. ARRAY_SIZE(genius_start_commands));
  548. }
  549. static int start_genius_videocam_live(struct gspca_dev *gspca_dev)
  550. {
  551. int r;
  552. struct sd *sd = (struct sd *) gspca_dev;
  553. struct init_command genius_vcam_live_start_commands[] = {
  554. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 0},
  555. {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  556. {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
  557. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
  558. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
  559. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  560. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  561. {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
  562. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  563. {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
  564. {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
  565. {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
  566. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  567. {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
  568. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  569. {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
  570. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  571. {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
  572. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  573. {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
  574. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  575. {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
  576. {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
  577. {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
  578. {{0x1c, 0x20, 0x00, 0x2d, 0x00, 0x00}, 4},
  579. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  580. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  581. {{0x13, 0x22, 0x01, 0x00, 0x00, 0x00}, 4},
  582. {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
  583. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  584. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
  585. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
  586. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  587. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  588. {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
  589. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  590. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  591. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  592. {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
  593. {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
  594. {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
  595. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  596. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  597. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  598. {{0x11, 0x01, 0x04, 0x00, 0x00, 0x00}, 4},
  599. {{0x11, 0x02, 0x92, 0x00, 0x00, 0x00}, 4},
  600. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  601. {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
  602. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  603. {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
  604. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  605. {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
  606. {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
  607. {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
  608. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  609. {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
  610. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  611. {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
  612. {{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
  613. {{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
  614. {{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
  615. {{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
  616. {{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
  617. {{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
  618. {{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
  619. {{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
  620. {{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
  621. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
  622. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
  623. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  624. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  625. {{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
  626. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  627. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  628. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  629. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  630. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  631. {{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
  632. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  633. {{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
  634. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  635. {{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
  636. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  637. {{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
  638. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  639. {{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
  640. {{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
  641. {{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
  642. {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
  643. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0},
  644. /* Camera should start to capture now. */
  645. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 0},
  646. {{0x1b, 0x32, 0x26, 0x00, 0x00, 0x00}, 0},
  647. {{0x1d, 0x25, 0x10, 0x20, 0xab, 0x00}, 0},
  648. };
  649. r = run_start_commands(gspca_dev, genius_vcam_live_start_commands,
  650. ARRAY_SIZE(genius_vcam_live_start_commands));
  651. if (r < 0)
  652. return r;
  653. if (sd->gain)
  654. set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd->gain));
  655. return r;
  656. }
  657. static int start_vivitar_cam(struct gspca_dev *gspca_dev)
  658. {
  659. struct init_command vivitar_start_commands[] = {
  660. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  661. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  662. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  663. {{0x13, 0x22, 0x01, 0x01, 0x00, 0x00}, 4},
  664. {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
  665. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  666. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
  667. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
  668. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  669. {{0x13, 0x28, 0x01, 0x0a, 0x00, 0x00}, 4},
  670. /*
  671. * Above is changed from OEM 0x0b. Fixes Bayer tiling.
  672. * Presumably gives a vertical shift of one row.
  673. */
  674. {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
  675. /* Above seems to do horizontal shift. */
  676. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  677. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  678. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  679. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  680. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  681. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  682. /* Above three commands seem to relate to brightness. */
  683. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  684. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  685. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  686. {{0x1b, 0x12, 0x80, 0x00, 0x00, 0x00}, 1},
  687. {{0x1b, 0x01, 0x77, 0x00, 0x00, 0x00}, 1},
  688. {{0x1b, 0x02, 0x3a, 0x00, 0x00, 0x00}, 1},
  689. {{0x1b, 0x12, 0x78, 0x00, 0x00, 0x00}, 1},
  690. {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
  691. {{0x1b, 0x14, 0x80, 0x00, 0x00, 0x00}, 1},
  692. {{0x1b, 0x15, 0x34, 0x00, 0x00, 0x00}, 1},
  693. {{0x1b, 0x1b, 0x04, 0x00, 0x00, 0x00}, 1},
  694. {{0x1b, 0x20, 0x44, 0x00, 0x00, 0x00}, 1},
  695. {{0x1b, 0x23, 0xee, 0x00, 0x00, 0x00}, 1},
  696. {{0x1b, 0x26, 0xa0, 0x00, 0x00, 0x00}, 1},
  697. {{0x1b, 0x27, 0x9a, 0x00, 0x00, 0x00}, 1},
  698. {{0x1b, 0x28, 0xa0, 0x00, 0x00, 0x00}, 1},
  699. {{0x1b, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
  700. {{0x1b, 0x2a, 0x80, 0x00, 0x00, 0x00}, 1},
  701. {{0x1b, 0x2b, 0x00, 0x00, 0x00, 0x00}, 1},
  702. {{0x1b, 0x2f, 0x3d, 0x00, 0x00, 0x00}, 1},
  703. {{0x1b, 0x30, 0x24, 0x00, 0x00, 0x00}, 1},
  704. {{0x1b, 0x32, 0x86, 0x00, 0x00, 0x00}, 1},
  705. {{0x1b, 0x60, 0xa9, 0x00, 0x00, 0x00}, 1},
  706. {{0x1b, 0x61, 0x42, 0x00, 0x00, 0x00}, 1},
  707. {{0x1b, 0x65, 0x00, 0x00, 0x00, 0x00}, 1},
  708. {{0x1b, 0x69, 0x38, 0x00, 0x00, 0x00}, 1},
  709. {{0x1b, 0x6f, 0x88, 0x00, 0x00, 0x00}, 1},
  710. {{0x1b, 0x70, 0x0b, 0x00, 0x00, 0x00}, 1},
  711. {{0x1b, 0x71, 0x00, 0x00, 0x00, 0x00}, 1},
  712. {{0x1b, 0x74, 0x21, 0x00, 0x00, 0x00}, 1},
  713. {{0x1b, 0x75, 0x86, 0x00, 0x00, 0x00}, 1},
  714. {{0x1b, 0x76, 0x00, 0x00, 0x00, 0x00}, 1},
  715. {{0x1b, 0x7d, 0xf3, 0x00, 0x00, 0x00}, 1},
  716. {{0x1b, 0x17, 0x1c, 0x00, 0x00, 0x00}, 1},
  717. {{0x1b, 0x18, 0xc0, 0x00, 0x00, 0x00}, 1},
  718. {{0x1b, 0x19, 0x05, 0x00, 0x00, 0x00}, 1},
  719. {{0x1b, 0x1a, 0xf6, 0x00, 0x00, 0x00}, 1},
  720. /* {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
  721. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
  722. {{0x13, 0x28, 0x01, 0x0b, 0x00, 0x00}, 4}, */
  723. {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
  724. {{0x1b, 0x10, 0x26, 0x00, 0x00, 0x00}, 1},
  725. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
  726. {{0x1b, 0x76, 0x03, 0x00, 0x00, 0x00}, 1},
  727. {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
  728. {{0x1b, 0x00, 0x3f, 0x00, 0x00, 0x00}, 1},
  729. /* Above is brightness; OEM driver setting is 0x10 */
  730. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
  731. {{0x20, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
  732. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}
  733. };
  734. return run_start_commands(gspca_dev, vivitar_start_commands,
  735. ARRAY_SIZE(vivitar_start_commands));
  736. }
  737. static int sd_start(struct gspca_dev *gspca_dev)
  738. {
  739. struct sd *sd = (struct sd *) gspca_dev;
  740. int err_code;
  741. sd->sof_read = 0;
  742. switch (sd->model) {
  743. case 0x7005:
  744. err_code = start_genius_cam(gspca_dev);
  745. break;
  746. case 0x7003:
  747. err_code = start_genius_videocam_live(gspca_dev);
  748. break;
  749. case 0x8001:
  750. err_code = start_spy_cam(gspca_dev);
  751. break;
  752. case 0x8003:
  753. err_code = start_cif_cam(gspca_dev);
  754. break;
  755. case 0x8008:
  756. err_code = start_ms350_cam(gspca_dev);
  757. break;
  758. case 0x800a:
  759. err_code = start_vivitar_cam(gspca_dev);
  760. break;
  761. default:
  762. pr_err("Starting unknown camera, please report this\n");
  763. return -ENXIO;
  764. }
  765. sd->avg_lum = -1;
  766. return err_code;
  767. }
  768. static void sd_stopN(struct gspca_dev *gspca_dev)
  769. {
  770. int result;
  771. __u8 data[6];
  772. result = sn9c2028_read1(gspca_dev);
  773. if (result < 0)
  774. gspca_err(gspca_dev, "Camera Stop read failed\n");
  775. memset(data, 0, 6);
  776. data[0] = 0x14;
  777. result = sn9c2028_command(gspca_dev, data);
  778. if (result < 0)
  779. gspca_err(gspca_dev, "Camera Stop command failed\n");
  780. }
  781. static void do_autogain(struct gspca_dev *gspca_dev, int avg_lum)
  782. {
  783. struct sd *sd = (struct sd *) gspca_dev;
  784. s32 cur_gain = v4l2_ctrl_g_ctrl(sd->gain);
  785. if (avg_lum == -1)
  786. return;
  787. if (avg_lum < MIN_AVG_LUM) {
  788. if (cur_gain == sd->gain->maximum)
  789. return;
  790. cur_gain++;
  791. v4l2_ctrl_s_ctrl(sd->gain, cur_gain);
  792. }
  793. if (avg_lum > MAX_AVG_LUM) {
  794. if (cur_gain == sd->gain->minimum)
  795. return;
  796. cur_gain--;
  797. v4l2_ctrl_s_ctrl(sd->gain, cur_gain);
  798. }
  799. }
  800. static void sd_dqcallback(struct gspca_dev *gspca_dev)
  801. {
  802. struct sd *sd = (struct sd *) gspca_dev;
  803. if (sd->autogain == NULL || !v4l2_ctrl_g_ctrl(sd->autogain))
  804. return;
  805. do_autogain(gspca_dev, sd->avg_lum);
  806. }
  807. /* Include sn9c2028 sof detection functions */
  808. #include "sn9c2028.h"
  809. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  810. __u8 *data, /* isoc packet */
  811. int len) /* iso packet length */
  812. {
  813. unsigned char *sof;
  814. sof = sn9c2028_find_sof(gspca_dev, data, len);
  815. if (sof) {
  816. int n;
  817. /* finish decoding current frame */
  818. n = sof - data;
  819. if (n > sizeof sn9c2028_sof_marker)
  820. n -= sizeof sn9c2028_sof_marker;
  821. else
  822. n = 0;
  823. gspca_frame_add(gspca_dev, LAST_PACKET, data, n);
  824. /* Start next frame. */
  825. gspca_frame_add(gspca_dev, FIRST_PACKET,
  826. sn9c2028_sof_marker, sizeof sn9c2028_sof_marker);
  827. len -= sof - data;
  828. data = sof;
  829. }
  830. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  831. }
  832. /* sub-driver description */
  833. static const struct sd_desc sd_desc = {
  834. .name = MODULE_NAME,
  835. .config = sd_config,
  836. .init = sd_init,
  837. .init_controls = sd_init_controls,
  838. .start = sd_start,
  839. .stopN = sd_stopN,
  840. .dq_callback = sd_dqcallback,
  841. .pkt_scan = sd_pkt_scan,
  842. };
  843. /* -- module initialisation -- */
  844. static const struct usb_device_id device_table[] = {
  845. {USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */
  846. {USB_DEVICE(0x0458, 0x7003)}, /* Genius Videocam Live v2 */
  847. /* The Genius Smart is untested. I can't find an owner ! */
  848. /* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */
  849. {USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */
  850. {USB_DEVICE(0x0c45, 0x8003)}, /* Several small CIF cameras */
  851. /* {USB_DEVICE(0x0c45, 0x8006)}, Unknown VGA camera */
  852. {USB_DEVICE(0x0c45, 0x8008)}, /* Mini-Shotz ms-350 */
  853. {USB_DEVICE(0x0c45, 0x800a)}, /* Vivicam 3350B */
  854. {}
  855. };
  856. MODULE_DEVICE_TABLE(usb, device_table);
  857. /* -- device connect -- */
  858. static int sd_probe(struct usb_interface *intf,
  859. const struct usb_device_id *id)
  860. {
  861. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  862. THIS_MODULE);
  863. }
  864. static struct usb_driver sd_driver = {
  865. .name = MODULE_NAME,
  866. .id_table = device_table,
  867. .probe = sd_probe,
  868. .disconnect = gspca_disconnect,
  869. #ifdef CONFIG_PM
  870. .suspend = gspca_suspend,
  871. .resume = gspca_resume,
  872. .reset_resume = gspca_resume,
  873. #endif
  874. };
  875. module_usb_driver(sd_driver);