sn9c2028.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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 MODULE_NAME "sn9c2028"
  21. #include "gspca.h"
  22. MODULE_AUTHOR("Theodore Kilgore");
  23. MODULE_DESCRIPTION("Sonix SN9C2028 USB Camera Driver");
  24. MODULE_LICENSE("GPL");
  25. /* specific webcam descriptor */
  26. struct sd {
  27. struct gspca_dev gspca_dev; /* !! must be the first item */
  28. u8 sof_read;
  29. u16 model;
  30. };
  31. struct init_command {
  32. unsigned char instruction[6];
  33. unsigned char to_read; /* length to read. 0 means no reply requested */
  34. };
  35. /* V4L2 controls supported by the driver */
  36. static const struct ctrl sd_ctrls[] = {
  37. };
  38. /* How to change the resolution of any of the VGA cams is unknown */
  39. static const struct v4l2_pix_format vga_mode[] = {
  40. {640, 480, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
  41. .bytesperline = 640,
  42. .sizeimage = 640 * 480 * 3 / 4,
  43. .colorspace = V4L2_COLORSPACE_SRGB,
  44. .priv = 0},
  45. };
  46. /* No way to change the resolution of the CIF cams is known */
  47. static const struct v4l2_pix_format cif_mode[] = {
  48. {352, 288, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
  49. .bytesperline = 352,
  50. .sizeimage = 352 * 288 * 3 / 4,
  51. .colorspace = V4L2_COLORSPACE_SRGB,
  52. .priv = 0},
  53. };
  54. /* the bytes to write are in gspca_dev->usb_buf */
  55. static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command)
  56. {
  57. int rc;
  58. PDEBUG(D_USBO, "sending command %02x%02x%02x%02x%02x%02x", command[0],
  59. command[1], command[2], command[3], command[4], command[5]);
  60. memcpy(gspca_dev->usb_buf, command, 6);
  61. rc = usb_control_msg(gspca_dev->dev,
  62. usb_sndctrlpipe(gspca_dev->dev, 0),
  63. USB_REQ_GET_CONFIGURATION,
  64. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  65. 2, 0, gspca_dev->usb_buf, 6, 500);
  66. if (rc < 0) {
  67. err("command write [%02x] error %d",
  68. gspca_dev->usb_buf[0], rc);
  69. return rc;
  70. }
  71. return 0;
  72. }
  73. static int sn9c2028_read1(struct gspca_dev *gspca_dev)
  74. {
  75. int rc;
  76. rc = usb_control_msg(gspca_dev->dev,
  77. usb_rcvctrlpipe(gspca_dev->dev, 0),
  78. USB_REQ_GET_STATUS,
  79. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  80. 1, 0, gspca_dev->usb_buf, 1, 500);
  81. if (rc != 1) {
  82. err("read1 error %d", rc);
  83. return (rc < 0) ? rc : -EIO;
  84. }
  85. PDEBUG(D_USBI, "read1 response %02x", gspca_dev->usb_buf[0]);
  86. return gspca_dev->usb_buf[0];
  87. }
  88. static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading)
  89. {
  90. int rc;
  91. rc = usb_control_msg(gspca_dev->dev,
  92. usb_rcvctrlpipe(gspca_dev->dev, 0),
  93. USB_REQ_GET_STATUS,
  94. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  95. 4, 0, gspca_dev->usb_buf, 4, 500);
  96. if (rc != 4) {
  97. err("read4 error %d", rc);
  98. return (rc < 0) ? rc : -EIO;
  99. }
  100. memcpy(reading, gspca_dev->usb_buf, 4);
  101. PDEBUG(D_USBI, "read4 response %02x%02x%02x%02x", reading[0],
  102. reading[1], reading[2], reading[3]);
  103. return rc;
  104. }
  105. static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command)
  106. {
  107. int i, status;
  108. __u8 reading[4];
  109. status = sn9c2028_command(gspca_dev, command);
  110. if (status < 0)
  111. return status;
  112. status = -1;
  113. for (i = 0; i < 256 && status < 2; i++)
  114. status = sn9c2028_read1(gspca_dev);
  115. if (status != 2) {
  116. err("long command status read error %d", status);
  117. return (status < 0) ? status : -EIO;
  118. }
  119. memset(reading, 0, 4);
  120. status = sn9c2028_read4(gspca_dev, reading);
  121. if (status < 0)
  122. return status;
  123. /* in general, the first byte of the response is the first byte of
  124. * the command, or'ed with 8 */
  125. status = sn9c2028_read1(gspca_dev);
  126. if (status < 0)
  127. return status;
  128. return 0;
  129. }
  130. static int sn9c2028_short_command(struct gspca_dev *gspca_dev, u8 *command)
  131. {
  132. int err_code;
  133. err_code = sn9c2028_command(gspca_dev, command);
  134. if (err_code < 0)
  135. return err_code;
  136. err_code = sn9c2028_read1(gspca_dev);
  137. if (err_code < 0)
  138. return err_code;
  139. return 0;
  140. }
  141. /* this function is called at probe time */
  142. static int sd_config(struct gspca_dev *gspca_dev,
  143. const struct usb_device_id *id)
  144. {
  145. struct sd *sd = (struct sd *) gspca_dev;
  146. struct cam *cam = &gspca_dev->cam;
  147. PDEBUG(D_PROBE, "SN9C2028 camera detected (vid/pid 0x%04X:0x%04X)",
  148. id->idVendor, id->idProduct);
  149. sd->model = id->idProduct;
  150. switch (sd->model) {
  151. case 0x7005:
  152. PDEBUG(D_PROBE, "Genius Smart 300 camera");
  153. break;
  154. case 0x8000:
  155. PDEBUG(D_PROBE, "DC31VC");
  156. break;
  157. case 0x8001:
  158. PDEBUG(D_PROBE, "Spy camera");
  159. break;
  160. case 0x8003:
  161. PDEBUG(D_PROBE, "CIF camera");
  162. break;
  163. case 0x8008:
  164. PDEBUG(D_PROBE, "Mini-Shotz ms-350 camera");
  165. break;
  166. case 0x800a:
  167. PDEBUG(D_PROBE, "Vivitar 3350b type camera");
  168. cam->input_flags = V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  169. break;
  170. }
  171. switch (sd->model) {
  172. case 0x8000:
  173. case 0x8001:
  174. case 0x8003:
  175. cam->cam_mode = cif_mode;
  176. cam->nmodes = ARRAY_SIZE(cif_mode);
  177. break;
  178. default:
  179. cam->cam_mode = vga_mode;
  180. cam->nmodes = ARRAY_SIZE(vga_mode);
  181. }
  182. return 0;
  183. }
  184. /* this function is called at probe and resume time */
  185. static int sd_init(struct gspca_dev *gspca_dev)
  186. {
  187. int status = -1;
  188. sn9c2028_read1(gspca_dev);
  189. sn9c2028_read1(gspca_dev);
  190. status = sn9c2028_read1(gspca_dev);
  191. return (status < 0) ? status : 0;
  192. }
  193. static int run_start_commands(struct gspca_dev *gspca_dev,
  194. struct init_command *cam_commands, int n)
  195. {
  196. int i, err_code = -1;
  197. for (i = 0; i < n; i++) {
  198. switch (cam_commands[i].to_read) {
  199. case 4:
  200. err_code = sn9c2028_long_command(gspca_dev,
  201. cam_commands[i].instruction);
  202. break;
  203. case 1:
  204. err_code = sn9c2028_short_command(gspca_dev,
  205. cam_commands[i].instruction);
  206. break;
  207. case 0:
  208. err_code = sn9c2028_command(gspca_dev,
  209. cam_commands[i].instruction);
  210. break;
  211. }
  212. if (err_code < 0)
  213. return err_code;
  214. }
  215. return 0;
  216. }
  217. static int start_spy_cam(struct gspca_dev *gspca_dev)
  218. {
  219. struct init_command spy_start_commands[] = {
  220. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  221. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  222. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  223. {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
  224. {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
  225. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  226. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, /* width 352 */
  227. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, /* height 288 */
  228. /* {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, */
  229. {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4},
  230. {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* red gain ?*/
  231. /* {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, */
  232. {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
  233. /* {{0x13, 0x29, 0x01, 0x0c, 0x00, 0x00}, 4}, */
  234. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  235. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  236. /* {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, */
  237. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  238. {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
  239. /* {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, */
  240. {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
  241. {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
  242. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  243. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  244. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  245. {{0x11, 0x02, 0x06, 0x00, 0x00, 0x00}, 4},
  246. {{0x11, 0x03, 0x13, 0x00, 0x00, 0x00}, 4}, /*don't mess with*/
  247. /*{{0x11, 0x04, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
  248. {{0x11, 0x04, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
  249. /*{{0x11, 0x05, 0x65, 0x00, 0x00, 0x00}, 4}, observed */
  250. {{0x11, 0x05, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
  251. {{0x11, 0x06, 0xb1, 0x00, 0x00, 0x00}, 4}, /* observed */
  252. {{0x11, 0x07, 0x00, 0x00, 0x00, 0x00}, 4},
  253. /*{{0x11, 0x08, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
  254. {{0x11, 0x08, 0x0b, 0x00, 0x00, 0x00}, 4},
  255. {{0x11, 0x09, 0x01, 0x00, 0x00, 0x00}, 4},
  256. {{0x11, 0x0a, 0x01, 0x00, 0x00, 0x00}, 4},
  257. {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
  258. {{0x11, 0x0c, 0x01, 0x00, 0x00, 0x00}, 4},
  259. {{0x11, 0x0d, 0x00, 0x00, 0x00, 0x00}, 4},
  260. {{0x11, 0x0e, 0x04, 0x00, 0x00, 0x00}, 4},
  261. /* {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4}, */
  262. /* brightness or gain. 0 is default. 4 is good
  263. * indoors at night with incandescent lighting */
  264. {{0x11, 0x0f, 0x04, 0x00, 0x00, 0x00}, 4},
  265. {{0x11, 0x10, 0x06, 0x00, 0x00, 0x00}, 4}, /*hstart or hoffs*/
  266. {{0x11, 0x11, 0x06, 0x00, 0x00, 0x00}, 4},
  267. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  268. {{0x11, 0x14, 0x02, 0x00, 0x00, 0x00}, 4},
  269. {{0x11, 0x13, 0x01, 0x00, 0x00, 0x00}, 4},
  270. /* {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, observed */
  271. {{0x1b, 0x02, 0x11, 0x00, 0x00, 0x00}, 1}, /* brighter */
  272. /* {{0x1b, 0x13, 0x01, 0x00, 0x00, 0x00}, 1}, observed */
  273. {{0x1b, 0x13, 0x11, 0x00, 0x00, 0x00}, 1},
  274. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}, /* compresses */
  275. /* Camera should start to capture now. */
  276. };
  277. return run_start_commands(gspca_dev, spy_start_commands,
  278. ARRAY_SIZE(spy_start_commands));
  279. }
  280. static int start_cif_cam(struct gspca_dev *gspca_dev)
  281. {
  282. struct init_command cif_start_commands[] = {
  283. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  284. /* The entire sequence below seems redundant */
  285. /* {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  286. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  287. {{0x13, 0x22, 0x01, 0x06, 0x00, 0x00}, 4},
  288. {{0x13, 0x23, 0x01, 0x02, 0x00, 0x00}, 4},
  289. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  290. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, width?
  291. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, height?
  292. {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
  293. {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
  294. {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
  295. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  296. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  297. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  298. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  299. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  300. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  301. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  302. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  303. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},*/
  304. {{0x1b, 0x21, 0x00, 0x00, 0x00, 0x00}, 1},
  305. {{0x1b, 0x17, 0x00, 0x00, 0x00, 0x00}, 1},
  306. {{0x1b, 0x19, 0x00, 0x00, 0x00, 0x00}, 1},
  307. {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
  308. {{0x1b, 0x03, 0x5a, 0x00, 0x00, 0x00}, 1},
  309. {{0x1b, 0x04, 0x27, 0x00, 0x00, 0x00}, 1},
  310. {{0x1b, 0x05, 0x01, 0x00, 0x00, 0x00}, 1},
  311. {{0x1b, 0x12, 0x14, 0x00, 0x00, 0x00}, 1},
  312. {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
  313. {{0x1b, 0x14, 0x00, 0x00, 0x00, 0x00}, 1},
  314. {{0x1b, 0x15, 0x00, 0x00, 0x00, 0x00}, 1},
  315. {{0x1b, 0x16, 0x00, 0x00, 0x00, 0x00}, 1},
  316. {{0x1b, 0x77, 0xa2, 0x00, 0x00, 0x00}, 1},
  317. {{0x1b, 0x06, 0x0f, 0x00, 0x00, 0x00}, 1},
  318. {{0x1b, 0x07, 0x14, 0x00, 0x00, 0x00}, 1},
  319. {{0x1b, 0x08, 0x0f, 0x00, 0x00, 0x00}, 1},
  320. {{0x1b, 0x09, 0x10, 0x00, 0x00, 0x00}, 1},
  321. {{0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00}, 1},
  322. {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
  323. {{0x1b, 0x12, 0x07, 0x00, 0x00, 0x00}, 1},
  324. {{0x1b, 0x10, 0x1f, 0x00, 0x00, 0x00}, 1},
  325. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
  326. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 1}, /* width/8 */
  327. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 1}, /* height/8 */
  328. /* {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
  329. * {{0x13, 0x28, 0x01, 0x1e, 0x00, 0x00}, 4}, does nothing
  330. * {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, */
  331. /* {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
  332. * causes subsampling
  333. * but not a change in the resolution setting! */
  334. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  335. {{0x13, 0x2d, 0x01, 0x01, 0x00, 0x00}, 4},
  336. {{0x13, 0x2e, 0x01, 0x08, 0x00, 0x00}, 4},
  337. {{0x13, 0x2f, 0x01, 0x06, 0x00, 0x00}, 4},
  338. {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
  339. {{0x1b, 0x04, 0x6d, 0x00, 0x00, 0x00}, 1},
  340. {{0x1b, 0x05, 0x03, 0x00, 0x00, 0x00}, 1},
  341. {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
  342. {{0x1b, 0x0e, 0x01, 0x00, 0x00, 0x00}, 1},
  343. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
  344. {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
  345. {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
  346. {{0x1b, 0x10, 0x0f, 0x00, 0x00, 0x00}, 1},
  347. {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
  348. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
  349. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1},/* use compression */
  350. /* Camera should start to capture now. */
  351. };
  352. return run_start_commands(gspca_dev, cif_start_commands,
  353. ARRAY_SIZE(cif_start_commands));
  354. }
  355. static int start_ms350_cam(struct gspca_dev *gspca_dev)
  356. {
  357. struct init_command ms350_start_commands[] = {
  358. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  359. {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  360. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  361. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  362. {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
  363. {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
  364. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  365. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
  366. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
  367. {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
  368. {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4},
  369. {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
  370. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  371. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  372. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  373. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  374. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  375. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  376. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  377. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  378. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  379. {{0x11, 0x00, 0x01, 0x00, 0x00, 0x00}, 4},
  380. {{0x11, 0x01, 0x70, 0x00, 0x00, 0x00}, 4},
  381. {{0x11, 0x02, 0x05, 0x00, 0x00, 0x00}, 4},
  382. {{0x11, 0x03, 0x5d, 0x00, 0x00, 0x00}, 4},
  383. {{0x11, 0x04, 0x07, 0x00, 0x00, 0x00}, 4},
  384. {{0x11, 0x05, 0x25, 0x00, 0x00, 0x00}, 4},
  385. {{0x11, 0x06, 0x00, 0x00, 0x00, 0x00}, 4},
  386. {{0x11, 0x07, 0x09, 0x00, 0x00, 0x00}, 4},
  387. {{0x11, 0x08, 0x01, 0x00, 0x00, 0x00}, 4},
  388. {{0x11, 0x09, 0x00, 0x00, 0x00, 0x00}, 4},
  389. {{0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, 4},
  390. {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
  391. {{0x11, 0x0c, 0x00, 0x00, 0x00, 0x00}, 4},
  392. {{0x11, 0x0d, 0x0c, 0x00, 0x00, 0x00}, 4},
  393. {{0x11, 0x0e, 0x01, 0x00, 0x00, 0x00}, 4},
  394. {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4},
  395. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  396. {{0x11, 0x11, 0x00, 0x00, 0x00, 0x00}, 4},
  397. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  398. {{0x11, 0x13, 0x63, 0x00, 0x00, 0x00}, 4},
  399. {{0x11, 0x15, 0x70, 0x00, 0x00, 0x00}, 4},
  400. {{0x11, 0x18, 0x00, 0x00, 0x00, 0x00}, 4},
  401. {{0x11, 0x11, 0x01, 0x00, 0x00, 0x00}, 4},
  402. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* width */
  403. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* height */
  404. {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* vstart? */
  405. {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
  406. {{0x13, 0x29, 0x01, 0x40, 0x00, 0x00}, 4}, /* hstart? */
  407. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  408. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  409. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  410. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  411. {{0x1b, 0x02, 0x05, 0x00, 0x00, 0x00}, 1},
  412. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
  413. {{0x20, 0x18, 0x00, 0x00, 0x00, 0x00}, 1},
  414. {{0x1b, 0x02, 0x0a, 0x00, 0x00, 0x00}, 1},
  415. {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 0},
  416. /* Camera should start to capture now. */
  417. };
  418. return run_start_commands(gspca_dev, ms350_start_commands,
  419. ARRAY_SIZE(ms350_start_commands));
  420. }
  421. static int start_genius_cam(struct gspca_dev *gspca_dev)
  422. {
  423. struct init_command genius_start_commands[] = {
  424. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  425. {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  426. {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
  427. {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
  428. {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
  429. /* "preliminary" width and height settings */
  430. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  431. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  432. {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
  433. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  434. {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
  435. {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
  436. {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
  437. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  438. {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
  439. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  440. {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
  441. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  442. {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
  443. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  444. {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
  445. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  446. {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
  447. {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
  448. {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
  449. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  450. {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
  451. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  452. {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
  453. {{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
  454. {{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
  455. {{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
  456. {{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
  457. {{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
  458. {{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
  459. {{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
  460. {{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
  461. {{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
  462. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* real width */
  463. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* real height */
  464. {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
  465. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  466. {{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
  467. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  468. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  469. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  470. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  471. {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
  472. {{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
  473. {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
  474. {{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
  475. {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
  476. {{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
  477. {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
  478. {{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
  479. {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
  480. {{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
  481. {{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
  482. {{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
  483. {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
  484. {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
  485. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0}
  486. /* Camera should start to capture now. */
  487. };
  488. return run_start_commands(gspca_dev, genius_start_commands,
  489. ARRAY_SIZE(genius_start_commands));
  490. }
  491. static int start_vivitar_cam(struct gspca_dev *gspca_dev)
  492. {
  493. struct init_command vivitar_start_commands[] = {
  494. {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
  495. {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
  496. {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
  497. {{0x13, 0x22, 0x01, 0x01, 0x00, 0x00}, 4},
  498. {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
  499. {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
  500. {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
  501. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
  502. {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
  503. {{0x13, 0x28, 0x01, 0x0a, 0x00, 0x00}, 4},
  504. /*
  505. * Above is changed from OEM 0x0b. Fixes Bayer tiling.
  506. * Presumably gives a vertical shift of one row.
  507. */
  508. {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
  509. /* Above seems to do horizontal shift. */
  510. {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
  511. {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
  512. {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
  513. {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
  514. {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
  515. {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
  516. /* Above three commands seem to relate to brightness. */
  517. {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
  518. {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
  519. {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
  520. {{0x1b, 0x12, 0x80, 0x00, 0x00, 0x00}, 1},
  521. {{0x1b, 0x01, 0x77, 0x00, 0x00, 0x00}, 1},
  522. {{0x1b, 0x02, 0x3a, 0x00, 0x00, 0x00}, 1},
  523. {{0x1b, 0x12, 0x78, 0x00, 0x00, 0x00}, 1},
  524. {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
  525. {{0x1b, 0x14, 0x80, 0x00, 0x00, 0x00}, 1},
  526. {{0x1b, 0x15, 0x34, 0x00, 0x00, 0x00}, 1},
  527. {{0x1b, 0x1b, 0x04, 0x00, 0x00, 0x00}, 1},
  528. {{0x1b, 0x20, 0x44, 0x00, 0x00, 0x00}, 1},
  529. {{0x1b, 0x23, 0xee, 0x00, 0x00, 0x00}, 1},
  530. {{0x1b, 0x26, 0xa0, 0x00, 0x00, 0x00}, 1},
  531. {{0x1b, 0x27, 0x9a, 0x00, 0x00, 0x00}, 1},
  532. {{0x1b, 0x28, 0xa0, 0x00, 0x00, 0x00}, 1},
  533. {{0x1b, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
  534. {{0x1b, 0x2a, 0x80, 0x00, 0x00, 0x00}, 1},
  535. {{0x1b, 0x2b, 0x00, 0x00, 0x00, 0x00}, 1},
  536. {{0x1b, 0x2f, 0x3d, 0x00, 0x00, 0x00}, 1},
  537. {{0x1b, 0x30, 0x24, 0x00, 0x00, 0x00}, 1},
  538. {{0x1b, 0x32, 0x86, 0x00, 0x00, 0x00}, 1},
  539. {{0x1b, 0x60, 0xa9, 0x00, 0x00, 0x00}, 1},
  540. {{0x1b, 0x61, 0x42, 0x00, 0x00, 0x00}, 1},
  541. {{0x1b, 0x65, 0x00, 0x00, 0x00, 0x00}, 1},
  542. {{0x1b, 0x69, 0x38, 0x00, 0x00, 0x00}, 1},
  543. {{0x1b, 0x6f, 0x88, 0x00, 0x00, 0x00}, 1},
  544. {{0x1b, 0x70, 0x0b, 0x00, 0x00, 0x00}, 1},
  545. {{0x1b, 0x71, 0x00, 0x00, 0x00, 0x00}, 1},
  546. {{0x1b, 0x74, 0x21, 0x00, 0x00, 0x00}, 1},
  547. {{0x1b, 0x75, 0x86, 0x00, 0x00, 0x00}, 1},
  548. {{0x1b, 0x76, 0x00, 0x00, 0x00, 0x00}, 1},
  549. {{0x1b, 0x7d, 0xf3, 0x00, 0x00, 0x00}, 1},
  550. {{0x1b, 0x17, 0x1c, 0x00, 0x00, 0x00}, 1},
  551. {{0x1b, 0x18, 0xc0, 0x00, 0x00, 0x00}, 1},
  552. {{0x1b, 0x19, 0x05, 0x00, 0x00, 0x00}, 1},
  553. {{0x1b, 0x1a, 0xf6, 0x00, 0x00, 0x00}, 1},
  554. /* {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
  555. {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
  556. {{0x13, 0x28, 0x01, 0x0b, 0x00, 0x00}, 4}, */
  557. {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
  558. {{0x1b, 0x10, 0x26, 0x00, 0x00, 0x00}, 1},
  559. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
  560. {{0x1b, 0x76, 0x03, 0x00, 0x00, 0x00}, 1},
  561. {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
  562. {{0x1b, 0x00, 0x3f, 0x00, 0x00, 0x00}, 1},
  563. /* Above is brightness; OEM driver setting is 0x10 */
  564. {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
  565. {{0x20, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
  566. {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}
  567. };
  568. return run_start_commands(gspca_dev, vivitar_start_commands,
  569. ARRAY_SIZE(vivitar_start_commands));
  570. }
  571. static int sd_start(struct gspca_dev *gspca_dev)
  572. {
  573. struct sd *sd = (struct sd *) gspca_dev;
  574. int err_code;
  575. sd->sof_read = 0;
  576. switch (sd->model) {
  577. case 0x7005:
  578. err_code = start_genius_cam(gspca_dev);
  579. break;
  580. case 0x8001:
  581. err_code = start_spy_cam(gspca_dev);
  582. break;
  583. case 0x8003:
  584. err_code = start_cif_cam(gspca_dev);
  585. break;
  586. case 0x8008:
  587. err_code = start_ms350_cam(gspca_dev);
  588. break;
  589. case 0x800a:
  590. err_code = start_vivitar_cam(gspca_dev);
  591. break;
  592. default:
  593. err("Starting unknown camera, please report this");
  594. return -ENXIO;
  595. }
  596. return err_code;
  597. }
  598. static void sd_stopN(struct gspca_dev *gspca_dev)
  599. {
  600. int result;
  601. __u8 data[6];
  602. result = sn9c2028_read1(gspca_dev);
  603. if (result < 0)
  604. PDEBUG(D_ERR, "Camera Stop read failed");
  605. memset(data, 0, 6);
  606. data[0] = 0x14;
  607. result = sn9c2028_command(gspca_dev, data);
  608. if (result < 0)
  609. PDEBUG(D_ERR, "Camera Stop command failed");
  610. }
  611. /* Include sn9c2028 sof detection functions */
  612. #include "sn9c2028.h"
  613. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  614. __u8 *data, /* isoc packet */
  615. int len) /* iso packet length */
  616. {
  617. unsigned char *sof;
  618. sof = sn9c2028_find_sof(gspca_dev, data, len);
  619. if (sof) {
  620. int n;
  621. /* finish decoding current frame */
  622. n = sof - data;
  623. if (n > sizeof sn9c2028_sof_marker)
  624. n -= sizeof sn9c2028_sof_marker;
  625. else
  626. n = 0;
  627. gspca_frame_add(gspca_dev, LAST_PACKET, data, n);
  628. /* Start next frame. */
  629. gspca_frame_add(gspca_dev, FIRST_PACKET,
  630. sn9c2028_sof_marker, sizeof sn9c2028_sof_marker);
  631. len -= sof - data;
  632. data = sof;
  633. }
  634. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  635. }
  636. /* sub-driver description */
  637. static const struct sd_desc sd_desc = {
  638. .name = MODULE_NAME,
  639. .ctrls = sd_ctrls,
  640. .nctrls = ARRAY_SIZE(sd_ctrls),
  641. .config = sd_config,
  642. .init = sd_init,
  643. .start = sd_start,
  644. .stopN = sd_stopN,
  645. .pkt_scan = sd_pkt_scan,
  646. };
  647. /* -- module initialisation -- */
  648. static const struct usb_device_id device_table[] = {
  649. {USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */
  650. /* The Genius Smart is untested. I can't find an owner ! */
  651. /* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */
  652. {USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */
  653. {USB_DEVICE(0x0c45, 0x8003)}, /* Several small CIF cameras */
  654. /* {USB_DEVICE(0x0c45, 0x8006)}, Unknown VGA camera */
  655. {USB_DEVICE(0x0c45, 0x8008)}, /* Mini-Shotz ms-350 */
  656. {USB_DEVICE(0x0c45, 0x800a)}, /* Vivicam 3350B */
  657. {}
  658. };
  659. MODULE_DEVICE_TABLE(usb, device_table);
  660. /* -- device connect -- */
  661. static int sd_probe(struct usb_interface *intf,
  662. const struct usb_device_id *id)
  663. {
  664. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  665. THIS_MODULE);
  666. }
  667. static struct usb_driver sd_driver = {
  668. .name = MODULE_NAME,
  669. .id_table = device_table,
  670. .probe = sd_probe,
  671. .disconnect = gspca_disconnect,
  672. #ifdef CONFIG_PM
  673. .suspend = gspca_suspend,
  674. .resume = gspca_resume,
  675. #endif
  676. };
  677. /* -- module insert / remove -- */
  678. static int __init sd_mod_init(void)
  679. {
  680. return usb_register(&sd_driver);
  681. }
  682. static void __exit sd_mod_exit(void)
  683. {
  684. usb_deregister(&sd_driver);
  685. }
  686. module_init(sd_mod_init);
  687. module_exit(sd_mod_exit);