cpia2_v4l.c 34 KB

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