cpia2_v4l.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /****************************************************************************
  2. *
  3. * Filename: cpia2_v4l.c
  4. *
  5. * Copyright 2001, STMicrolectronics, Inc.
  6. * Contact: steve.miller@st.com
  7. * Copyright 2001,2005, Scott J. Bertin <scottbertin@yahoo.com>
  8. *
  9. * Description:
  10. * This is a USB driver for CPia2 based video cameras.
  11. * The infrastructure of this driver is based on the cpia usb driver by
  12. * Jochen Scharrlach and Johannes Erdfeldt.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * Stripped of 2.4 stuff ready for main kernel submit by
  25. * Alan Cox <alan@lxorguk.ukuu.org.uk>
  26. ****************************************************************************/
  27. #define CPIA_VERSION "3.0.1"
  28. #include <linux/module.h>
  29. #include <linux/time.h>
  30. #include <linux/sched.h>
  31. #include <linux/slab.h>
  32. #include <linux/init.h>
  33. #include <linux/videodev2.h>
  34. #include <linux/stringify.h>
  35. #include <media/v4l2-ioctl.h>
  36. #include <media/v4l2-event.h>
  37. #include "cpia2.h"
  38. static int video_nr = -1;
  39. module_param(video_nr, int, 0);
  40. MODULE_PARM_DESC(video_nr, "video device to register (0=/dev/video0, etc)");
  41. static int buffer_size = 68 * 1024;
  42. module_param(buffer_size, int, 0);
  43. MODULE_PARM_DESC(buffer_size, "Size for each frame buffer in bytes (default 68k)");
  44. static int num_buffers = 3;
  45. module_param(num_buffers, int, 0);
  46. MODULE_PARM_DESC(num_buffers, "Number of frame buffers (1-"
  47. __stringify(VIDEO_MAX_FRAME) ", default 3)");
  48. static int alternate = DEFAULT_ALT;
  49. module_param(alternate, int, 0);
  50. MODULE_PARM_DESC(alternate, "USB Alternate (" __stringify(USBIF_ISO_1) "-"
  51. __stringify(USBIF_ISO_6) ", default "
  52. __stringify(DEFAULT_ALT) ")");
  53. static int flicker_mode;
  54. module_param(flicker_mode, int, 0);
  55. MODULE_PARM_DESC(flicker_mode, "Flicker frequency (0 (disabled), " __stringify(50) " or "
  56. __stringify(60) ", default 0)");
  57. MODULE_AUTHOR("Steve Miller (STMicroelectronics) <steve.miller@st.com>");
  58. MODULE_DESCRIPTION("V4L-driver for STMicroelectronics CPiA2 based cameras");
  59. MODULE_SUPPORTED_DEVICE("video");
  60. MODULE_LICENSE("GPL");
  61. MODULE_VERSION(CPIA_VERSION);
  62. #define ABOUT "V4L-Driver for Vision CPiA2 based cameras"
  63. #define CPIA2_CID_USB_ALT (V4L2_CID_USER_BASE | 0xf000)
  64. /******************************************************************************
  65. *
  66. * cpia2_open
  67. *
  68. *****************************************************************************/
  69. static int cpia2_open(struct file *file)
  70. {
  71. struct camera_data *cam = video_drvdata(file);
  72. int retval;
  73. if (mutex_lock_interruptible(&cam->v4l2_lock))
  74. return -ERESTARTSYS;
  75. retval = v4l2_fh_open(file);
  76. if (retval)
  77. goto open_unlock;
  78. if (v4l2_fh_is_singular_file(file)) {
  79. if (cpia2_allocate_buffers(cam)) {
  80. v4l2_fh_release(file);
  81. retval = -ENOMEM;
  82. goto open_unlock;
  83. }
  84. /* reset the camera */
  85. if (cpia2_reset_camera(cam) < 0) {
  86. v4l2_fh_release(file);
  87. retval = -EIO;
  88. goto open_unlock;
  89. }
  90. cam->APP_len = 0;
  91. cam->COM_len = 0;
  92. }
  93. cpia2_dbg_dump_registers(cam);
  94. open_unlock:
  95. mutex_unlock(&cam->v4l2_lock);
  96. return retval;
  97. }
  98. /******************************************************************************
  99. *
  100. * cpia2_close
  101. *
  102. *****************************************************************************/
  103. static int cpia2_close(struct file *file)
  104. {
  105. struct video_device *dev = video_devdata(file);
  106. struct camera_data *cam = video_get_drvdata(dev);
  107. mutex_lock(&cam->v4l2_lock);
  108. if (video_is_registered(&cam->vdev) && v4l2_fh_is_singular_file(file)) {
  109. cpia2_usb_stream_stop(cam);
  110. /* save camera state for later open */
  111. cpia2_save_camera_state(cam);
  112. cpia2_set_low_power(cam);
  113. cpia2_free_buffers(cam);
  114. }
  115. if (cam->stream_fh == file->private_data) {
  116. cam->stream_fh = NULL;
  117. cam->mmapped = 0;
  118. }
  119. mutex_unlock(&cam->v4l2_lock);
  120. return v4l2_fh_release(file);
  121. }
  122. /******************************************************************************
  123. *
  124. * cpia2_v4l_read
  125. *
  126. *****************************************************************************/
  127. static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
  128. loff_t *off)
  129. {
  130. struct camera_data *cam = video_drvdata(file);
  131. int noblock = file->f_flags&O_NONBLOCK;
  132. ssize_t ret;
  133. if(!cam)
  134. return -EINVAL;
  135. if (mutex_lock_interruptible(&cam->v4l2_lock))
  136. return -ERESTARTSYS;
  137. ret = cpia2_read(cam, buf, count, noblock);
  138. mutex_unlock(&cam->v4l2_lock);
  139. return ret;
  140. }
  141. /******************************************************************************
  142. *
  143. * cpia2_v4l_poll
  144. *
  145. *****************************************************************************/
  146. static __poll_t cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
  147. {
  148. struct camera_data *cam = video_drvdata(filp);
  149. __poll_t res;
  150. mutex_lock(&cam->v4l2_lock);
  151. res = cpia2_poll(cam, filp, wait);
  152. mutex_unlock(&cam->v4l2_lock);
  153. return res;
  154. }
  155. static int sync(struct camera_data *cam, int frame_nr)
  156. {
  157. struct framebuf *frame = &cam->buffers[frame_nr];
  158. while (1) {
  159. if (frame->status == FRAME_READY)
  160. return 0;
  161. if (!cam->streaming) {
  162. frame->status = FRAME_READY;
  163. frame->length = 0;
  164. return 0;
  165. }
  166. mutex_unlock(&cam->v4l2_lock);
  167. wait_event_interruptible(cam->wq_stream,
  168. !cam->streaming ||
  169. frame->status == FRAME_READY);
  170. mutex_lock(&cam->v4l2_lock);
  171. if (signal_pending(current))
  172. return -ERESTARTSYS;
  173. if (!video_is_registered(&cam->vdev))
  174. return -ENOTTY;
  175. }
  176. }
  177. /******************************************************************************
  178. *
  179. * ioctl_querycap
  180. *
  181. * V4L2 device capabilities
  182. *
  183. *****************************************************************************/
  184. static int cpia2_querycap(struct file *file, void *fh, struct v4l2_capability *vc)
  185. {
  186. struct camera_data *cam = video_drvdata(file);
  187. strcpy(vc->driver, "cpia2");
  188. if (cam->params.pnp_id.product == 0x151)
  189. strcpy(vc->card, "QX5 Microscope");
  190. else
  191. strcpy(vc->card, "CPiA2 Camera");
  192. switch (cam->params.pnp_id.device_type) {
  193. case DEVICE_STV_672:
  194. strcat(vc->card, " (672/");
  195. break;
  196. case DEVICE_STV_676:
  197. strcat(vc->card, " (676/");
  198. break;
  199. default:
  200. strcat(vc->card, " (XXX/");
  201. break;
  202. }
  203. switch (cam->params.version.sensor_flags) {
  204. case CPIA2_VP_SENSOR_FLAGS_404:
  205. strcat(vc->card, "404)");
  206. break;
  207. case CPIA2_VP_SENSOR_FLAGS_407:
  208. strcat(vc->card, "407)");
  209. break;
  210. case CPIA2_VP_SENSOR_FLAGS_409:
  211. strcat(vc->card, "409)");
  212. break;
  213. case CPIA2_VP_SENSOR_FLAGS_410:
  214. strcat(vc->card, "410)");
  215. break;
  216. case CPIA2_VP_SENSOR_FLAGS_500:
  217. strcat(vc->card, "500)");
  218. break;
  219. default:
  220. strcat(vc->card, "XXX)");
  221. break;
  222. }
  223. if (usb_make_path(cam->dev, vc->bus_info, sizeof(vc->bus_info)) <0)
  224. memset(vc->bus_info,0, sizeof(vc->bus_info));
  225. vc->device_caps = V4L2_CAP_VIDEO_CAPTURE |
  226. V4L2_CAP_READWRITE |
  227. V4L2_CAP_STREAMING;
  228. vc->capabilities = vc->device_caps |
  229. V4L2_CAP_DEVICE_CAPS;
  230. return 0;
  231. }
  232. /******************************************************************************
  233. *
  234. * ioctl_input
  235. *
  236. * V4L2 input get/set/enumerate
  237. *
  238. *****************************************************************************/
  239. static int cpia2_enum_input(struct file *file, void *fh, struct v4l2_input *i)
  240. {
  241. if (i->index)
  242. return -EINVAL;
  243. strcpy(i->name, "Camera");
  244. i->type = V4L2_INPUT_TYPE_CAMERA;
  245. return 0;
  246. }
  247. static int cpia2_g_input(struct file *file, void *fh, unsigned int *i)
  248. {
  249. *i = 0;
  250. return 0;
  251. }
  252. static int cpia2_s_input(struct file *file, void *fh, unsigned int i)
  253. {
  254. return i ? -EINVAL : 0;
  255. }
  256. /******************************************************************************
  257. *
  258. * ioctl_enum_fmt
  259. *
  260. * V4L2 format enumerate
  261. *
  262. *****************************************************************************/
  263. static int cpia2_enum_fmt_vid_cap(struct file *file, void *fh,
  264. struct v4l2_fmtdesc *f)
  265. {
  266. int index = f->index;
  267. if (index < 0 || index > 1)
  268. return -EINVAL;
  269. memset(f, 0, sizeof(*f));
  270. f->index = index;
  271. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  272. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  273. switch(index) {
  274. case 0:
  275. strcpy(f->description, "MJPEG");
  276. f->pixelformat = V4L2_PIX_FMT_MJPEG;
  277. break;
  278. case 1:
  279. strcpy(f->description, "JPEG");
  280. f->pixelformat = V4L2_PIX_FMT_JPEG;
  281. break;
  282. default:
  283. return -EINVAL;
  284. }
  285. return 0;
  286. }
  287. /******************************************************************************
  288. *
  289. * ioctl_try_fmt
  290. *
  291. * V4L2 format try
  292. *
  293. *****************************************************************************/
  294. static int cpia2_try_fmt_vid_cap(struct file *file, void *fh,
  295. struct v4l2_format *f)
  296. {
  297. struct camera_data *cam = video_drvdata(file);
  298. if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG &&
  299. f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
  300. return -EINVAL;
  301. f->fmt.pix.field = V4L2_FIELD_NONE;
  302. f->fmt.pix.bytesperline = 0;
  303. f->fmt.pix.sizeimage = cam->frame_size;
  304. f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  305. f->fmt.pix.priv = 0;
  306. switch (cpia2_match_video_size(f->fmt.pix.width, f->fmt.pix.height)) {
  307. case VIDEOSIZE_VGA:
  308. f->fmt.pix.width = 640;
  309. f->fmt.pix.height = 480;
  310. break;
  311. case VIDEOSIZE_CIF:
  312. f->fmt.pix.width = 352;
  313. f->fmt.pix.height = 288;
  314. break;
  315. case VIDEOSIZE_QVGA:
  316. f->fmt.pix.width = 320;
  317. f->fmt.pix.height = 240;
  318. break;
  319. case VIDEOSIZE_288_216:
  320. f->fmt.pix.width = 288;
  321. f->fmt.pix.height = 216;
  322. break;
  323. case VIDEOSIZE_256_192:
  324. f->fmt.pix.width = 256;
  325. f->fmt.pix.height = 192;
  326. break;
  327. case VIDEOSIZE_224_168:
  328. f->fmt.pix.width = 224;
  329. f->fmt.pix.height = 168;
  330. break;
  331. case VIDEOSIZE_192_144:
  332. f->fmt.pix.width = 192;
  333. f->fmt.pix.height = 144;
  334. break;
  335. case VIDEOSIZE_QCIF:
  336. default:
  337. f->fmt.pix.width = 176;
  338. f->fmt.pix.height = 144;
  339. break;
  340. }
  341. return 0;
  342. }
  343. /******************************************************************************
  344. *
  345. * ioctl_set_fmt
  346. *
  347. * V4L2 format set
  348. *
  349. *****************************************************************************/
  350. static int cpia2_s_fmt_vid_cap(struct file *file, void *_fh,
  351. struct v4l2_format *f)
  352. {
  353. struct camera_data *cam = video_drvdata(file);
  354. int err, frame;
  355. err = cpia2_try_fmt_vid_cap(file, _fh, f);
  356. if(err != 0)
  357. return err;
  358. cam->pixelformat = f->fmt.pix.pixelformat;
  359. /* NOTE: This should be set to 1 for MJPEG, but some apps don't handle
  360. * the missing Huffman table properly. */
  361. cam->params.compression.inhibit_htables = 0;
  362. /*f->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG;*/
  363. /* we set the video window to something smaller or equal to what
  364. * is requested by the user???
  365. */
  366. DBG("Requested width = %d, height = %d\n",
  367. f->fmt.pix.width, f->fmt.pix.height);
  368. if (f->fmt.pix.width != cam->width ||
  369. f->fmt.pix.height != cam->height) {
  370. cam->width = f->fmt.pix.width;
  371. cam->height = f->fmt.pix.height;
  372. cam->params.roi.width = f->fmt.pix.width;
  373. cam->params.roi.height = f->fmt.pix.height;
  374. cpia2_set_format(cam);
  375. }
  376. for (frame = 0; frame < cam->num_frames; ++frame) {
  377. if (cam->buffers[frame].status == FRAME_READING)
  378. if ((err = sync(cam, frame)) < 0)
  379. return err;
  380. cam->buffers[frame].status = FRAME_EMPTY;
  381. }
  382. return 0;
  383. }
  384. /******************************************************************************
  385. *
  386. * ioctl_get_fmt
  387. *
  388. * V4L2 format get
  389. *
  390. *****************************************************************************/
  391. static int cpia2_g_fmt_vid_cap(struct file *file, void *fh,
  392. struct v4l2_format *f)
  393. {
  394. struct camera_data *cam = video_drvdata(file);
  395. f->fmt.pix.width = cam->width;
  396. f->fmt.pix.height = cam->height;
  397. f->fmt.pix.pixelformat = cam->pixelformat;
  398. f->fmt.pix.field = V4L2_FIELD_NONE;
  399. f->fmt.pix.bytesperline = 0;
  400. f->fmt.pix.sizeimage = cam->frame_size;
  401. f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  402. f->fmt.pix.priv = 0;
  403. return 0;
  404. }
  405. /******************************************************************************
  406. *
  407. * ioctl_cropcap
  408. *
  409. * V4L2 query cropping capabilities
  410. * NOTE: cropping is currently disabled
  411. *
  412. *****************************************************************************/
  413. static int cpia2_cropcap(struct file *file, void *fh, struct v4l2_cropcap *c)
  414. {
  415. struct camera_data *cam = video_drvdata(file);
  416. if (c->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  417. return -EINVAL;
  418. c->bounds.left = 0;
  419. c->bounds.top = 0;
  420. c->bounds.width = cam->width;
  421. c->bounds.height = cam->height;
  422. c->defrect.left = 0;
  423. c->defrect.top = 0;
  424. c->defrect.width = cam->width;
  425. c->defrect.height = cam->height;
  426. c->pixelaspect.numerator = 1;
  427. c->pixelaspect.denominator = 1;
  428. return 0;
  429. }
  430. struct framerate_info {
  431. int value;
  432. struct v4l2_fract period;
  433. };
  434. static const struct framerate_info framerate_controls[] = {
  435. { CPIA2_VP_FRAMERATE_6_25, { 4, 25 } },
  436. { CPIA2_VP_FRAMERATE_7_5, { 2, 15 } },
  437. { CPIA2_VP_FRAMERATE_12_5, { 2, 25 } },
  438. { CPIA2_VP_FRAMERATE_15, { 1, 15 } },
  439. { CPIA2_VP_FRAMERATE_25, { 1, 25 } },
  440. { CPIA2_VP_FRAMERATE_30, { 1, 30 } },
  441. };
  442. static int cpia2_g_parm(struct file *file, void *fh, struct v4l2_streamparm *p)
  443. {
  444. struct camera_data *cam = video_drvdata(file);
  445. struct v4l2_captureparm *cap = &p->parm.capture;
  446. int i;
  447. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  448. return -EINVAL;
  449. cap->capability = V4L2_CAP_TIMEPERFRAME;
  450. cap->readbuffers = cam->num_frames;
  451. for (i = 0; i < ARRAY_SIZE(framerate_controls); i++)
  452. if (cam->params.vp_params.frame_rate == framerate_controls[i].value) {
  453. cap->timeperframe = framerate_controls[i].period;
  454. break;
  455. }
  456. return 0;
  457. }
  458. static int cpia2_s_parm(struct file *file, void *fh, struct v4l2_streamparm *p)
  459. {
  460. struct camera_data *cam = video_drvdata(file);
  461. struct v4l2_captureparm *cap = &p->parm.capture;
  462. struct v4l2_fract tpf = cap->timeperframe;
  463. int max = ARRAY_SIZE(framerate_controls) - 1;
  464. int ret;
  465. int i;
  466. ret = cpia2_g_parm(file, fh, p);
  467. if (ret || !tpf.denominator || !tpf.numerator)
  468. return ret;
  469. /* Maximum 15 fps for this model */
  470. if (cam->params.pnp_id.device_type == DEVICE_STV_672 &&
  471. cam->params.version.sensor_flags == CPIA2_VP_SENSOR_FLAGS_500)
  472. max -= 2;
  473. for (i = 0; i <= max; i++) {
  474. struct v4l2_fract f1 = tpf;
  475. struct v4l2_fract f2 = framerate_controls[i].period;
  476. f1.numerator *= f2.denominator;
  477. f2.numerator *= f1.denominator;
  478. if (f1.numerator >= f2.numerator)
  479. break;
  480. }
  481. if (i > max)
  482. i = max;
  483. cap->timeperframe = framerate_controls[i].period;
  484. return cpia2_set_fps(cam, framerate_controls[i].value);
  485. }
  486. static const struct {
  487. u32 width;
  488. u32 height;
  489. } cpia2_framesizes[] = {
  490. { 640, 480 },
  491. { 352, 288 },
  492. { 320, 240 },
  493. { 288, 216 },
  494. { 256, 192 },
  495. { 224, 168 },
  496. { 192, 144 },
  497. { 176, 144 },
  498. };
  499. static int cpia2_enum_framesizes(struct file *file, void *fh,
  500. struct v4l2_frmsizeenum *fsize)
  501. {
  502. if (fsize->pixel_format != V4L2_PIX_FMT_MJPEG &&
  503. fsize->pixel_format != V4L2_PIX_FMT_JPEG)
  504. return -EINVAL;
  505. if (fsize->index >= ARRAY_SIZE(cpia2_framesizes))
  506. return -EINVAL;
  507. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  508. fsize->discrete.width = cpia2_framesizes[fsize->index].width;
  509. fsize->discrete.height = cpia2_framesizes[fsize->index].height;
  510. return 0;
  511. }
  512. static int cpia2_enum_frameintervals(struct file *file, void *fh,
  513. struct v4l2_frmivalenum *fival)
  514. {
  515. struct camera_data *cam = video_drvdata(file);
  516. int max = ARRAY_SIZE(framerate_controls) - 1;
  517. int i;
  518. if (fival->pixel_format != V4L2_PIX_FMT_MJPEG &&
  519. fival->pixel_format != V4L2_PIX_FMT_JPEG)
  520. return -EINVAL;
  521. /* Maximum 15 fps for this model */
  522. if (cam->params.pnp_id.device_type == DEVICE_STV_672 &&
  523. cam->params.version.sensor_flags == CPIA2_VP_SENSOR_FLAGS_500)
  524. max -= 2;
  525. if (fival->index > max)
  526. return -EINVAL;
  527. for (i = 0; i < ARRAY_SIZE(cpia2_framesizes); i++)
  528. if (fival->width == cpia2_framesizes[i].width &&
  529. fival->height == cpia2_framesizes[i].height)
  530. break;
  531. if (i == ARRAY_SIZE(cpia2_framesizes))
  532. return -EINVAL;
  533. fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  534. fival->discrete = framerate_controls[fival->index].period;
  535. return 0;
  536. }
  537. /******************************************************************************
  538. *
  539. * ioctl_s_ctrl
  540. *
  541. * V4L2 set the value of a control variable
  542. *
  543. *****************************************************************************/
  544. static int cpia2_s_ctrl(struct v4l2_ctrl *ctrl)
  545. {
  546. struct camera_data *cam =
  547. container_of(ctrl->handler, struct camera_data, hdl);
  548. static const int flicker_table[] = {
  549. NEVER_FLICKER,
  550. FLICKER_50,
  551. FLICKER_60,
  552. };
  553. DBG("Set control id:%d, value:%d\n", ctrl->id, ctrl->val);
  554. switch (ctrl->id) {
  555. case V4L2_CID_BRIGHTNESS:
  556. cpia2_set_brightness(cam, ctrl->val);
  557. break;
  558. case V4L2_CID_CONTRAST:
  559. cpia2_set_contrast(cam, ctrl->val);
  560. break;
  561. case V4L2_CID_SATURATION:
  562. cpia2_set_saturation(cam, ctrl->val);
  563. break;
  564. case V4L2_CID_HFLIP:
  565. cpia2_set_property_mirror(cam, ctrl->val);
  566. break;
  567. case V4L2_CID_VFLIP:
  568. cpia2_set_property_flip(cam, ctrl->val);
  569. break;
  570. case V4L2_CID_POWER_LINE_FREQUENCY:
  571. return cpia2_set_flicker_mode(cam, flicker_table[ctrl->val]);
  572. case V4L2_CID_ILLUMINATORS_1:
  573. return cpia2_set_gpio(cam, (cam->top_light->val << 6) |
  574. (cam->bottom_light->val << 7));
  575. case V4L2_CID_JPEG_ACTIVE_MARKER:
  576. cam->params.compression.inhibit_htables =
  577. !(ctrl->val & V4L2_JPEG_ACTIVE_MARKER_DHT);
  578. break;
  579. case V4L2_CID_JPEG_COMPRESSION_QUALITY:
  580. cam->params.vc_params.quality = ctrl->val;
  581. break;
  582. case CPIA2_CID_USB_ALT:
  583. cam->params.camera_state.stream_mode = ctrl->val;
  584. break;
  585. default:
  586. return -EINVAL;
  587. }
  588. return 0;
  589. }
  590. /******************************************************************************
  591. *
  592. * ioctl_g_jpegcomp
  593. *
  594. * V4L2 get the JPEG compression parameters
  595. *
  596. *****************************************************************************/
  597. static int cpia2_g_jpegcomp(struct file *file, void *fh, struct v4l2_jpegcompression *parms)
  598. {
  599. struct camera_data *cam = video_drvdata(file);
  600. memset(parms, 0, sizeof(*parms));
  601. parms->quality = 80; // TODO: Can this be made meaningful?
  602. parms->jpeg_markers = V4L2_JPEG_MARKER_DQT | V4L2_JPEG_MARKER_DRI;
  603. if(!cam->params.compression.inhibit_htables) {
  604. parms->jpeg_markers |= V4L2_JPEG_MARKER_DHT;
  605. }
  606. parms->APPn = cam->APPn;
  607. parms->APP_len = cam->APP_len;
  608. if(cam->APP_len > 0) {
  609. memcpy(parms->APP_data, cam->APP_data, cam->APP_len);
  610. parms->jpeg_markers |= V4L2_JPEG_MARKER_APP;
  611. }
  612. parms->COM_len = cam->COM_len;
  613. if(cam->COM_len > 0) {
  614. memcpy(parms->COM_data, cam->COM_data, cam->COM_len);
  615. parms->jpeg_markers |= JPEG_MARKER_COM;
  616. }
  617. DBG("G_JPEGCOMP APP_len:%d COM_len:%d\n",
  618. parms->APP_len, parms->COM_len);
  619. return 0;
  620. }
  621. /******************************************************************************
  622. *
  623. * ioctl_s_jpegcomp
  624. *
  625. * V4L2 set the JPEG compression parameters
  626. * NOTE: quality and some jpeg_markers are ignored.
  627. *
  628. *****************************************************************************/
  629. static int cpia2_s_jpegcomp(struct file *file, void *fh,
  630. const struct v4l2_jpegcompression *parms)
  631. {
  632. struct camera_data *cam = video_drvdata(file);
  633. DBG("S_JPEGCOMP APP_len:%d COM_len:%d\n",
  634. parms->APP_len, parms->COM_len);
  635. cam->params.compression.inhibit_htables =
  636. !(parms->jpeg_markers & V4L2_JPEG_MARKER_DHT);
  637. if(parms->APP_len != 0) {
  638. if(parms->APP_len > 0 &&
  639. parms->APP_len <= sizeof(cam->APP_data) &&
  640. parms->APPn >= 0 && parms->APPn <= 15) {
  641. cam->APPn = parms->APPn;
  642. cam->APP_len = parms->APP_len;
  643. memcpy(cam->APP_data, parms->APP_data, parms->APP_len);
  644. } else {
  645. LOG("Bad APPn Params n=%d len=%d\n",
  646. parms->APPn, parms->APP_len);
  647. return -EINVAL;
  648. }
  649. } else {
  650. cam->APP_len = 0;
  651. }
  652. if(parms->COM_len != 0) {
  653. if(parms->COM_len > 0 &&
  654. parms->COM_len <= sizeof(cam->COM_data)) {
  655. cam->COM_len = parms->COM_len;
  656. memcpy(cam->COM_data, parms->COM_data, parms->COM_len);
  657. } else {
  658. LOG("Bad COM_len=%d\n", parms->COM_len);
  659. return -EINVAL;
  660. }
  661. }
  662. return 0;
  663. }
  664. /******************************************************************************
  665. *
  666. * ioctl_reqbufs
  667. *
  668. * V4L2 Initiate memory mapping.
  669. * NOTE: The user's request is ignored. For now the buffers are fixed.
  670. *
  671. *****************************************************************************/
  672. static int cpia2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *req)
  673. {
  674. struct camera_data *cam = video_drvdata(file);
  675. if(req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  676. req->memory != V4L2_MEMORY_MMAP)
  677. return -EINVAL;
  678. DBG("REQBUFS requested:%d returning:%d\n", req->count, cam->num_frames);
  679. req->count = cam->num_frames;
  680. memset(&req->reserved, 0, sizeof(req->reserved));
  681. return 0;
  682. }
  683. /******************************************************************************
  684. *
  685. * ioctl_querybuf
  686. *
  687. * V4L2 Query memory buffer status.
  688. *
  689. *****************************************************************************/
  690. static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  691. {
  692. struct camera_data *cam = video_drvdata(file);
  693. if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  694. buf->index >= cam->num_frames)
  695. return -EINVAL;
  696. buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
  697. buf->length = cam->frame_size;
  698. buf->memory = V4L2_MEMORY_MMAP;
  699. if(cam->mmapped)
  700. buf->flags = V4L2_BUF_FLAG_MAPPED;
  701. else
  702. buf->flags = 0;
  703. buf->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  704. switch (cam->buffers[buf->index].status) {
  705. case FRAME_EMPTY:
  706. case FRAME_ERROR:
  707. case FRAME_READING:
  708. buf->bytesused = 0;
  709. buf->flags = V4L2_BUF_FLAG_QUEUED;
  710. break;
  711. case FRAME_READY:
  712. buf->bytesused = cam->buffers[buf->index].length;
  713. buf->timestamp = cam->buffers[buf->index].timestamp;
  714. buf->sequence = cam->buffers[buf->index].seq;
  715. buf->flags = V4L2_BUF_FLAG_DONE;
  716. break;
  717. }
  718. DBG("QUERYBUF index:%d offset:%d flags:%d seq:%d bytesused:%d\n",
  719. buf->index, buf->m.offset, buf->flags, buf->sequence,
  720. buf->bytesused);
  721. return 0;
  722. }
  723. /******************************************************************************
  724. *
  725. * ioctl_qbuf
  726. *
  727. * V4L2 User is freeing buffer
  728. *
  729. *****************************************************************************/
  730. static int cpia2_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  731. {
  732. struct camera_data *cam = video_drvdata(file);
  733. if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  734. buf->memory != V4L2_MEMORY_MMAP ||
  735. buf->index >= cam->num_frames)
  736. return -EINVAL;
  737. DBG("QBUF #%d\n", buf->index);
  738. if(cam->buffers[buf->index].status == FRAME_READY)
  739. cam->buffers[buf->index].status = FRAME_EMPTY;
  740. return 0;
  741. }
  742. /******************************************************************************
  743. *
  744. * find_earliest_filled_buffer
  745. *
  746. * Helper for ioctl_dqbuf. Find the next ready buffer.
  747. *
  748. *****************************************************************************/
  749. static int find_earliest_filled_buffer(struct camera_data *cam)
  750. {
  751. int i;
  752. int found = -1;
  753. for (i=0; i<cam->num_frames; i++) {
  754. if(cam->buffers[i].status == FRAME_READY) {
  755. if(found < 0) {
  756. found = i;
  757. } else {
  758. /* find which buffer is earlier */
  759. struct timeval *tv1, *tv2;
  760. tv1 = &cam->buffers[i].timestamp;
  761. tv2 = &cam->buffers[found].timestamp;
  762. if(tv1->tv_sec < tv2->tv_sec ||
  763. (tv1->tv_sec == tv2->tv_sec &&
  764. tv1->tv_usec < tv2->tv_usec))
  765. found = i;
  766. }
  767. }
  768. }
  769. return found;
  770. }
  771. /******************************************************************************
  772. *
  773. * ioctl_dqbuf
  774. *
  775. * V4L2 User is asking for a filled buffer.
  776. *
  777. *****************************************************************************/
  778. static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  779. {
  780. struct camera_data *cam = video_drvdata(file);
  781. int frame;
  782. if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  783. buf->memory != V4L2_MEMORY_MMAP)
  784. return -EINVAL;
  785. frame = find_earliest_filled_buffer(cam);
  786. if(frame < 0 && file->f_flags&O_NONBLOCK)
  787. return -EAGAIN;
  788. if(frame < 0) {
  789. /* Wait for a frame to become available */
  790. struct framebuf *cb=cam->curbuff;
  791. mutex_unlock(&cam->v4l2_lock);
  792. wait_event_interruptible(cam->wq_stream,
  793. !video_is_registered(&cam->vdev) ||
  794. (cb=cam->curbuff)->status == FRAME_READY);
  795. mutex_lock(&cam->v4l2_lock);
  796. if (signal_pending(current))
  797. return -ERESTARTSYS;
  798. if (!video_is_registered(&cam->vdev))
  799. return -ENOTTY;
  800. frame = cb->num;
  801. }
  802. buf->index = frame;
  803. buf->bytesused = cam->buffers[buf->index].length;
  804. buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE
  805. | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  806. buf->field = V4L2_FIELD_NONE;
  807. buf->timestamp = cam->buffers[buf->index].timestamp;
  808. buf->sequence = cam->buffers[buf->index].seq;
  809. buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
  810. buf->length = cam->frame_size;
  811. buf->reserved2 = 0;
  812. buf->reserved = 0;
  813. memset(&buf->timecode, 0, sizeof(buf->timecode));
  814. DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
  815. cam->buffers[buf->index].status, buf->sequence, buf->bytesused);
  816. return 0;
  817. }
  818. static int cpia2_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
  819. {
  820. struct camera_data *cam = video_drvdata(file);
  821. int ret = -EINVAL;
  822. DBG("VIDIOC_STREAMON, streaming=%d\n", cam->streaming);
  823. if (!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  824. return -EINVAL;
  825. if (!cam->streaming) {
  826. ret = cpia2_usb_stream_start(cam,
  827. cam->params.camera_state.stream_mode);
  828. if (!ret)
  829. v4l2_ctrl_grab(cam->usb_alt, true);
  830. }
  831. return ret;
  832. }
  833. static int cpia2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
  834. {
  835. struct camera_data *cam = video_drvdata(file);
  836. int ret = -EINVAL;
  837. DBG("VIDIOC_STREAMOFF, streaming=%d\n", cam->streaming);
  838. if (!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  839. return -EINVAL;
  840. if (cam->streaming) {
  841. ret = cpia2_usb_stream_stop(cam);
  842. if (!ret)
  843. v4l2_ctrl_grab(cam->usb_alt, false);
  844. }
  845. return ret;
  846. }
  847. /******************************************************************************
  848. *
  849. * cpia2_mmap
  850. *
  851. *****************************************************************************/
  852. static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
  853. {
  854. struct camera_data *cam = video_drvdata(file);
  855. int retval;
  856. if (mutex_lock_interruptible(&cam->v4l2_lock))
  857. return -ERESTARTSYS;
  858. retval = cpia2_remap_buffer(cam, area);
  859. if(!retval)
  860. cam->stream_fh = file->private_data;
  861. mutex_unlock(&cam->v4l2_lock);
  862. return retval;
  863. }
  864. /******************************************************************************
  865. *
  866. * reset_camera_struct_v4l
  867. *
  868. * Sets all values to the defaults
  869. *****************************************************************************/
  870. static void reset_camera_struct_v4l(struct camera_data *cam)
  871. {
  872. cam->width = cam->params.roi.width;
  873. cam->height = cam->params.roi.height;
  874. cam->frame_size = buffer_size;
  875. cam->num_frames = num_buffers;
  876. /* Flicker modes */
  877. cam->params.flicker_control.flicker_mode_req = flicker_mode;
  878. /* stream modes */
  879. cam->params.camera_state.stream_mode = alternate;
  880. cam->pixelformat = V4L2_PIX_FMT_JPEG;
  881. }
  882. static const struct v4l2_ioctl_ops cpia2_ioctl_ops = {
  883. .vidioc_querycap = cpia2_querycap,
  884. .vidioc_enum_input = cpia2_enum_input,
  885. .vidioc_g_input = cpia2_g_input,
  886. .vidioc_s_input = cpia2_s_input,
  887. .vidioc_enum_fmt_vid_cap = cpia2_enum_fmt_vid_cap,
  888. .vidioc_g_fmt_vid_cap = cpia2_g_fmt_vid_cap,
  889. .vidioc_s_fmt_vid_cap = cpia2_s_fmt_vid_cap,
  890. .vidioc_try_fmt_vid_cap = cpia2_try_fmt_vid_cap,
  891. .vidioc_g_jpegcomp = cpia2_g_jpegcomp,
  892. .vidioc_s_jpegcomp = cpia2_s_jpegcomp,
  893. .vidioc_cropcap = cpia2_cropcap,
  894. .vidioc_reqbufs = cpia2_reqbufs,
  895. .vidioc_querybuf = cpia2_querybuf,
  896. .vidioc_qbuf = cpia2_qbuf,
  897. .vidioc_dqbuf = cpia2_dqbuf,
  898. .vidioc_streamon = cpia2_streamon,
  899. .vidioc_streamoff = cpia2_streamoff,
  900. .vidioc_s_parm = cpia2_s_parm,
  901. .vidioc_g_parm = cpia2_g_parm,
  902. .vidioc_enum_framesizes = cpia2_enum_framesizes,
  903. .vidioc_enum_frameintervals = cpia2_enum_frameintervals,
  904. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  905. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  906. };
  907. /***
  908. * The v4l video device structure initialized for this device
  909. ***/
  910. static const struct v4l2_file_operations cpia2_fops = {
  911. .owner = THIS_MODULE,
  912. .open = cpia2_open,
  913. .release = cpia2_close,
  914. .read = cpia2_v4l_read,
  915. .poll = cpia2_v4l_poll,
  916. .unlocked_ioctl = video_ioctl2,
  917. .mmap = cpia2_mmap,
  918. };
  919. static const struct video_device cpia2_template = {
  920. /* I could not find any place for the old .initialize initializer?? */
  921. .name = "CPiA2 Camera",
  922. .fops = &cpia2_fops,
  923. .ioctl_ops = &cpia2_ioctl_ops,
  924. .release = video_device_release_empty,
  925. };
  926. void cpia2_camera_release(struct v4l2_device *v4l2_dev)
  927. {
  928. struct camera_data *cam =
  929. container_of(v4l2_dev, struct camera_data, v4l2_dev);
  930. v4l2_ctrl_handler_free(&cam->hdl);
  931. v4l2_device_unregister(&cam->v4l2_dev);
  932. kfree(cam);
  933. }
  934. static const struct v4l2_ctrl_ops cpia2_ctrl_ops = {
  935. .s_ctrl = cpia2_s_ctrl,
  936. };
  937. /******************************************************************************
  938. *
  939. * cpia2_register_camera
  940. *
  941. *****************************************************************************/
  942. int cpia2_register_camera(struct camera_data *cam)
  943. {
  944. struct v4l2_ctrl_handler *hdl = &cam->hdl;
  945. struct v4l2_ctrl_config cpia2_usb_alt = {
  946. .ops = &cpia2_ctrl_ops,
  947. .id = CPIA2_CID_USB_ALT,
  948. .name = "USB Alternate",
  949. .type = V4L2_CTRL_TYPE_INTEGER,
  950. .min = USBIF_ISO_1,
  951. .max = USBIF_ISO_6,
  952. .step = 1,
  953. };
  954. int ret;
  955. v4l2_ctrl_handler_init(hdl, 12);
  956. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  957. V4L2_CID_BRIGHTNESS,
  958. cam->params.pnp_id.device_type == DEVICE_STV_672 ? 1 : 0,
  959. 255, 1, DEFAULT_BRIGHTNESS);
  960. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  961. V4L2_CID_CONTRAST, 0, 255, 1, DEFAULT_CONTRAST);
  962. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  963. V4L2_CID_SATURATION, 0, 255, 1, DEFAULT_SATURATION);
  964. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  965. V4L2_CID_HFLIP, 0, 1, 1, 0);
  966. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  967. V4L2_CID_JPEG_ACTIVE_MARKER, 0,
  968. V4L2_JPEG_ACTIVE_MARKER_DHT, 0,
  969. V4L2_JPEG_ACTIVE_MARKER_DHT);
  970. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  971. V4L2_CID_JPEG_COMPRESSION_QUALITY, 1,
  972. 100, 1, 100);
  973. cpia2_usb_alt.def = alternate;
  974. cam->usb_alt = v4l2_ctrl_new_custom(hdl, &cpia2_usb_alt, NULL);
  975. /* VP5 Only */
  976. if (cam->params.pnp_id.device_type != DEVICE_STV_672)
  977. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  978. V4L2_CID_VFLIP, 0, 1, 1, 0);
  979. /* Flicker control only valid for 672 */
  980. if (cam->params.pnp_id.device_type == DEVICE_STV_672)
  981. v4l2_ctrl_new_std_menu(hdl, &cpia2_ctrl_ops,
  982. V4L2_CID_POWER_LINE_FREQUENCY,
  983. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0);
  984. /* Light control only valid for the QX5 Microscope */
  985. if (cam->params.pnp_id.product == 0x151) {
  986. cam->top_light = v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  987. V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0);
  988. cam->bottom_light = v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  989. V4L2_CID_ILLUMINATORS_2, 0, 1, 1, 0);
  990. v4l2_ctrl_cluster(2, &cam->top_light);
  991. }
  992. if (hdl->error) {
  993. ret = hdl->error;
  994. v4l2_ctrl_handler_free(hdl);
  995. return ret;
  996. }
  997. cam->vdev = cpia2_template;
  998. video_set_drvdata(&cam->vdev, cam);
  999. cam->vdev.lock = &cam->v4l2_lock;
  1000. cam->vdev.ctrl_handler = hdl;
  1001. cam->vdev.v4l2_dev = &cam->v4l2_dev;
  1002. reset_camera_struct_v4l(cam);
  1003. /* register v4l device */
  1004. if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
  1005. ERR("video_register_device failed\n");
  1006. return -ENODEV;
  1007. }
  1008. return 0;
  1009. }
  1010. /******************************************************************************
  1011. *
  1012. * cpia2_unregister_camera
  1013. *
  1014. *****************************************************************************/
  1015. void cpia2_unregister_camera(struct camera_data *cam)
  1016. {
  1017. video_unregister_device(&cam->vdev);
  1018. }
  1019. /******************************************************************************
  1020. *
  1021. * check_parameters
  1022. *
  1023. * Make sure that all user-supplied parameters are sensible
  1024. *****************************************************************************/
  1025. static void __init check_parameters(void)
  1026. {
  1027. if(buffer_size < PAGE_SIZE) {
  1028. buffer_size = PAGE_SIZE;
  1029. LOG("buffer_size too small, setting to %d\n", buffer_size);
  1030. } else if(buffer_size > 1024*1024) {
  1031. /* arbitrary upper limiit */
  1032. buffer_size = 1024*1024;
  1033. LOG("buffer_size ridiculously large, setting to %d\n",
  1034. buffer_size);
  1035. } else {
  1036. buffer_size += PAGE_SIZE-1;
  1037. buffer_size &= ~(PAGE_SIZE-1);
  1038. }
  1039. if(num_buffers < 1) {
  1040. num_buffers = 1;
  1041. LOG("num_buffers too small, setting to %d\n", num_buffers);
  1042. } else if(num_buffers > VIDEO_MAX_FRAME) {
  1043. num_buffers = VIDEO_MAX_FRAME;
  1044. LOG("num_buffers too large, setting to %d\n", num_buffers);
  1045. }
  1046. if(alternate < USBIF_ISO_1 || alternate > USBIF_ISO_6) {
  1047. alternate = DEFAULT_ALT;
  1048. LOG("alternate specified is invalid, using %d\n", alternate);
  1049. }
  1050. if (flicker_mode != 0 && flicker_mode != FLICKER_50 && flicker_mode != FLICKER_60) {
  1051. flicker_mode = 0;
  1052. LOG("Flicker mode specified is invalid, using %d\n",
  1053. flicker_mode);
  1054. }
  1055. DBG("Using %d buffers, each %d bytes, alternate=%d\n",
  1056. num_buffers, buffer_size, alternate);
  1057. }
  1058. /************ Module Stuff ***************/
  1059. /******************************************************************************
  1060. *
  1061. * cpia2_init/module_init
  1062. *
  1063. *****************************************************************************/
  1064. static int __init cpia2_init(void)
  1065. {
  1066. LOG("%s v%s\n",
  1067. ABOUT, CPIA_VERSION);
  1068. check_parameters();
  1069. return cpia2_usb_init();
  1070. }
  1071. /******************************************************************************
  1072. *
  1073. * cpia2_exit/module_exit
  1074. *
  1075. *****************************************************************************/
  1076. static void __exit cpia2_exit(void)
  1077. {
  1078. cpia2_usb_cleanup();
  1079. schedule_timeout(2 * HZ);
  1080. }
  1081. module_init(cpia2_init);
  1082. module_exit(cpia2_exit);