sn9c2028.c 32 KB

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