cpia2_v4l.c 33 KB

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