cpia2_v4l.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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,
  634. const struct v4l2_jpegcompression *parms)
  635. {
  636. struct camera_data *cam = video_drvdata(file);
  637. DBG("S_JPEGCOMP APP_len:%d COM_len:%d\n",
  638. parms->APP_len, parms->COM_len);
  639. cam->params.compression.inhibit_htables =
  640. !(parms->jpeg_markers & V4L2_JPEG_MARKER_DHT);
  641. if(parms->APP_len != 0) {
  642. if(parms->APP_len > 0 &&
  643. parms->APP_len <= sizeof(cam->APP_data) &&
  644. parms->APPn >= 0 && parms->APPn <= 15) {
  645. cam->APPn = parms->APPn;
  646. cam->APP_len = parms->APP_len;
  647. memcpy(cam->APP_data, parms->APP_data, parms->APP_len);
  648. } else {
  649. LOG("Bad APPn Params n=%d len=%d\n",
  650. parms->APPn, parms->APP_len);
  651. return -EINVAL;
  652. }
  653. } else {
  654. cam->APP_len = 0;
  655. }
  656. if(parms->COM_len != 0) {
  657. if(parms->COM_len > 0 &&
  658. parms->COM_len <= sizeof(cam->COM_data)) {
  659. cam->COM_len = parms->COM_len;
  660. memcpy(cam->COM_data, parms->COM_data, parms->COM_len);
  661. } else {
  662. LOG("Bad COM_len=%d\n", parms->COM_len);
  663. return -EINVAL;
  664. }
  665. }
  666. return 0;
  667. }
  668. /******************************************************************************
  669. *
  670. * ioctl_reqbufs
  671. *
  672. * V4L2 Initiate memory mapping.
  673. * NOTE: The user's request is ignored. For now the buffers are fixed.
  674. *
  675. *****************************************************************************/
  676. static int cpia2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *req)
  677. {
  678. struct camera_data *cam = video_drvdata(file);
  679. if(req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  680. req->memory != V4L2_MEMORY_MMAP)
  681. return -EINVAL;
  682. DBG("REQBUFS requested:%d returning:%d\n", req->count, cam->num_frames);
  683. req->count = cam->num_frames;
  684. memset(&req->reserved, 0, sizeof(req->reserved));
  685. return 0;
  686. }
  687. /******************************************************************************
  688. *
  689. * ioctl_querybuf
  690. *
  691. * V4L2 Query memory buffer status.
  692. *
  693. *****************************************************************************/
  694. static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  695. {
  696. struct camera_data *cam = video_drvdata(file);
  697. if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  698. buf->index >= cam->num_frames)
  699. return -EINVAL;
  700. buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
  701. buf->length = cam->frame_size;
  702. buf->memory = V4L2_MEMORY_MMAP;
  703. if(cam->mmapped)
  704. buf->flags = V4L2_BUF_FLAG_MAPPED;
  705. else
  706. buf->flags = 0;
  707. buf->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  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. | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  810. buf->field = V4L2_FIELD_NONE;
  811. buf->timestamp = cam->buffers[buf->index].timestamp;
  812. buf->sequence = cam->buffers[buf->index].seq;
  813. buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
  814. buf->length = cam->frame_size;
  815. buf->reserved2 = 0;
  816. buf->reserved = 0;
  817. memset(&buf->timecode, 0, sizeof(buf->timecode));
  818. DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
  819. cam->buffers[buf->index].status, buf->sequence, buf->bytesused);
  820. return 0;
  821. }
  822. static int cpia2_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
  823. {
  824. struct camera_data *cam = video_drvdata(file);
  825. int ret = -EINVAL;
  826. DBG("VIDIOC_STREAMON, streaming=%d\n", cam->streaming);
  827. if (!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  828. return -EINVAL;
  829. if (!cam->streaming) {
  830. ret = cpia2_usb_stream_start(cam,
  831. cam->params.camera_state.stream_mode);
  832. if (!ret)
  833. v4l2_ctrl_grab(cam->usb_alt, true);
  834. }
  835. return ret;
  836. }
  837. static int cpia2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
  838. {
  839. struct camera_data *cam = video_drvdata(file);
  840. int ret = -EINVAL;
  841. DBG("VIDIOC_STREAMOFF, streaming=%d\n", cam->streaming);
  842. if (!cam->mmapped || type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  843. return -EINVAL;
  844. if (cam->streaming) {
  845. ret = cpia2_usb_stream_stop(cam);
  846. if (!ret)
  847. v4l2_ctrl_grab(cam->usb_alt, false);
  848. }
  849. return ret;
  850. }
  851. /******************************************************************************
  852. *
  853. * cpia2_mmap
  854. *
  855. *****************************************************************************/
  856. static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
  857. {
  858. struct camera_data *cam = video_drvdata(file);
  859. int retval;
  860. if (mutex_lock_interruptible(&cam->v4l2_lock))
  861. return -ERESTARTSYS;
  862. retval = cpia2_remap_buffer(cam, area);
  863. if(!retval)
  864. cam->stream_fh = file->private_data;
  865. mutex_unlock(&cam->v4l2_lock);
  866. return retval;
  867. }
  868. /******************************************************************************
  869. *
  870. * reset_camera_struct_v4l
  871. *
  872. * Sets all values to the defaults
  873. *****************************************************************************/
  874. static void reset_camera_struct_v4l(struct camera_data *cam)
  875. {
  876. cam->width = cam->params.roi.width;
  877. cam->height = cam->params.roi.height;
  878. cam->frame_size = buffer_size;
  879. cam->num_frames = num_buffers;
  880. /* Flicker modes */
  881. cam->params.flicker_control.flicker_mode_req = flicker_mode;
  882. /* stream modes */
  883. cam->params.camera_state.stream_mode = alternate;
  884. cam->pixelformat = V4L2_PIX_FMT_JPEG;
  885. }
  886. static const struct v4l2_ioctl_ops cpia2_ioctl_ops = {
  887. .vidioc_querycap = cpia2_querycap,
  888. .vidioc_enum_input = cpia2_enum_input,
  889. .vidioc_g_input = cpia2_g_input,
  890. .vidioc_s_input = cpia2_s_input,
  891. .vidioc_enum_fmt_vid_cap = cpia2_enum_fmt_vid_cap,
  892. .vidioc_g_fmt_vid_cap = cpia2_g_fmt_vid_cap,
  893. .vidioc_s_fmt_vid_cap = cpia2_s_fmt_vid_cap,
  894. .vidioc_try_fmt_vid_cap = cpia2_try_fmt_vid_cap,
  895. .vidioc_g_jpegcomp = cpia2_g_jpegcomp,
  896. .vidioc_s_jpegcomp = cpia2_s_jpegcomp,
  897. .vidioc_cropcap = cpia2_cropcap,
  898. .vidioc_reqbufs = cpia2_reqbufs,
  899. .vidioc_querybuf = cpia2_querybuf,
  900. .vidioc_qbuf = cpia2_qbuf,
  901. .vidioc_dqbuf = cpia2_dqbuf,
  902. .vidioc_streamon = cpia2_streamon,
  903. .vidioc_streamoff = cpia2_streamoff,
  904. .vidioc_s_parm = cpia2_s_parm,
  905. .vidioc_g_parm = cpia2_g_parm,
  906. .vidioc_enum_framesizes = cpia2_enum_framesizes,
  907. .vidioc_enum_frameintervals = cpia2_enum_frameintervals,
  908. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  909. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  910. };
  911. /***
  912. * The v4l video device structure initialized for this device
  913. ***/
  914. static const struct v4l2_file_operations cpia2_fops = {
  915. .owner = THIS_MODULE,
  916. .open = cpia2_open,
  917. .release = cpia2_close,
  918. .read = cpia2_v4l_read,
  919. .poll = cpia2_v4l_poll,
  920. .unlocked_ioctl = video_ioctl2,
  921. .mmap = cpia2_mmap,
  922. };
  923. static struct video_device cpia2_template = {
  924. /* I could not find any place for the old .initialize initializer?? */
  925. .name = "CPiA2 Camera",
  926. .fops = &cpia2_fops,
  927. .ioctl_ops = &cpia2_ioctl_ops,
  928. .release = video_device_release_empty,
  929. };
  930. void cpia2_camera_release(struct v4l2_device *v4l2_dev)
  931. {
  932. struct camera_data *cam =
  933. container_of(v4l2_dev, struct camera_data, v4l2_dev);
  934. v4l2_ctrl_handler_free(&cam->hdl);
  935. v4l2_device_unregister(&cam->v4l2_dev);
  936. kfree(cam);
  937. }
  938. static const struct v4l2_ctrl_ops cpia2_ctrl_ops = {
  939. .s_ctrl = cpia2_s_ctrl,
  940. };
  941. /******************************************************************************
  942. *
  943. * cpia2_register_camera
  944. *
  945. *****************************************************************************/
  946. int cpia2_register_camera(struct camera_data *cam)
  947. {
  948. struct v4l2_ctrl_handler *hdl = &cam->hdl;
  949. struct v4l2_ctrl_config cpia2_usb_alt = {
  950. .ops = &cpia2_ctrl_ops,
  951. .id = CPIA2_CID_USB_ALT,
  952. .name = "USB Alternate",
  953. .type = V4L2_CTRL_TYPE_INTEGER,
  954. .min = USBIF_ISO_1,
  955. .max = USBIF_ISO_6,
  956. .step = 1,
  957. };
  958. int ret;
  959. v4l2_ctrl_handler_init(hdl, 12);
  960. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  961. V4L2_CID_BRIGHTNESS,
  962. cam->params.pnp_id.device_type == DEVICE_STV_672 ? 1 : 0,
  963. 255, 1, DEFAULT_BRIGHTNESS);
  964. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  965. V4L2_CID_CONTRAST, 0, 255, 1, DEFAULT_CONTRAST);
  966. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  967. V4L2_CID_SATURATION, 0, 255, 1, DEFAULT_SATURATION);
  968. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  969. V4L2_CID_HFLIP, 0, 1, 1, 0);
  970. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  971. V4L2_CID_JPEG_ACTIVE_MARKER, 0,
  972. V4L2_JPEG_ACTIVE_MARKER_DHT, 0,
  973. V4L2_JPEG_ACTIVE_MARKER_DHT);
  974. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  975. V4L2_CID_JPEG_COMPRESSION_QUALITY, 1,
  976. 100, 1, 100);
  977. cpia2_usb_alt.def = alternate;
  978. cam->usb_alt = v4l2_ctrl_new_custom(hdl, &cpia2_usb_alt, NULL);
  979. /* VP5 Only */
  980. if (cam->params.pnp_id.device_type != DEVICE_STV_672)
  981. v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  982. V4L2_CID_VFLIP, 0, 1, 1, 0);
  983. /* Flicker control only valid for 672 */
  984. if (cam->params.pnp_id.device_type == DEVICE_STV_672)
  985. v4l2_ctrl_new_std_menu(hdl, &cpia2_ctrl_ops,
  986. V4L2_CID_POWER_LINE_FREQUENCY,
  987. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0);
  988. /* Light control only valid for the QX5 Microscope */
  989. if (cam->params.pnp_id.product == 0x151) {
  990. cam->top_light = v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  991. V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0);
  992. cam->bottom_light = v4l2_ctrl_new_std(hdl, &cpia2_ctrl_ops,
  993. V4L2_CID_ILLUMINATORS_2, 0, 1, 1, 0);
  994. v4l2_ctrl_cluster(2, &cam->top_light);
  995. }
  996. if (hdl->error) {
  997. ret = hdl->error;
  998. v4l2_ctrl_handler_free(hdl);
  999. return ret;
  1000. }
  1001. cam->vdev = cpia2_template;
  1002. video_set_drvdata(&cam->vdev, cam);
  1003. cam->vdev.lock = &cam->v4l2_lock;
  1004. cam->vdev.ctrl_handler = hdl;
  1005. cam->vdev.v4l2_dev = &cam->v4l2_dev;
  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);