bfin_capture.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /*
  2. * Analog Devices video capture driver
  3. *
  4. * Copyright (c) 2011 Analog Devices Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/completion.h>
  20. #include <linux/delay.h>
  21. #include <linux/errno.h>
  22. #include <linux/fs.h>
  23. #include <linux/i2c.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/mm.h>
  28. #include <linux/module.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/slab.h>
  31. #include <linux/time.h>
  32. #include <linux/types.h>
  33. #include <media/v4l2-chip-ident.h>
  34. #include <media/v4l2-common.h>
  35. #include <media/v4l2-ctrls.h>
  36. #include <media/v4l2-device.h>
  37. #include <media/v4l2-ioctl.h>
  38. #include <media/videobuf2-dma-contig.h>
  39. #include <asm/dma.h>
  40. #include <media/blackfin/bfin_capture.h>
  41. #include <media/blackfin/ppi.h>
  42. #define CAPTURE_DRV_NAME "bfin_capture"
  43. #define BCAP_MIN_NUM_BUF 2
  44. struct bcap_format {
  45. char *desc;
  46. u32 pixelformat;
  47. enum v4l2_mbus_pixelcode mbus_code;
  48. int bpp; /* bits per pixel */
  49. int dlen; /* data length for ppi in bits */
  50. };
  51. struct bcap_buffer {
  52. struct vb2_buffer vb;
  53. struct list_head list;
  54. };
  55. struct bcap_device {
  56. /* capture device instance */
  57. struct v4l2_device v4l2_dev;
  58. /* v4l2 control handler */
  59. struct v4l2_ctrl_handler ctrl_handler;
  60. /* device node data */
  61. struct video_device *video_dev;
  62. /* sub device instance */
  63. struct v4l2_subdev *sd;
  64. /* capture config */
  65. struct bfin_capture_config *cfg;
  66. /* ppi interface */
  67. struct ppi_if *ppi;
  68. /* current input */
  69. unsigned int cur_input;
  70. /* current selected standard */
  71. v4l2_std_id std;
  72. /* current selected dv_timings */
  73. struct v4l2_dv_timings dv_timings;
  74. /* used to store pixel format */
  75. struct v4l2_pix_format fmt;
  76. /* bits per pixel*/
  77. int bpp;
  78. /* data length for ppi in bits */
  79. int dlen;
  80. /* used to store sensor supported format */
  81. struct bcap_format *sensor_formats;
  82. /* number of sensor formats array */
  83. int num_sensor_formats;
  84. /* pointing to current video buffer */
  85. struct bcap_buffer *cur_frm;
  86. /* buffer queue used in videobuf2 */
  87. struct vb2_queue buffer_queue;
  88. /* allocator-specific contexts for each plane */
  89. struct vb2_alloc_ctx *alloc_ctx;
  90. /* queue of filled frames */
  91. struct list_head dma_queue;
  92. /* used in videobuf2 callback */
  93. spinlock_t lock;
  94. /* used to access capture device */
  95. struct mutex mutex;
  96. /* used to wait ppi to complete one transfer */
  97. struct completion comp;
  98. /* prepare to stop */
  99. bool stop;
  100. };
  101. struct bcap_fh {
  102. struct v4l2_fh fh;
  103. /* indicates whether this file handle is doing IO */
  104. bool io_allowed;
  105. };
  106. static const struct bcap_format bcap_formats[] = {
  107. {
  108. .desc = "YCbCr 4:2:2 Interleaved UYVY",
  109. .pixelformat = V4L2_PIX_FMT_UYVY,
  110. .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
  111. .bpp = 16,
  112. .dlen = 8,
  113. },
  114. {
  115. .desc = "YCbCr 4:2:2 Interleaved YUYV",
  116. .pixelformat = V4L2_PIX_FMT_YUYV,
  117. .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
  118. .bpp = 16,
  119. .dlen = 8,
  120. },
  121. {
  122. .desc = "YCbCr 4:2:2 Interleaved UYVY",
  123. .pixelformat = V4L2_PIX_FMT_UYVY,
  124. .mbus_code = V4L2_MBUS_FMT_UYVY8_1X16,
  125. .bpp = 16,
  126. .dlen = 16,
  127. },
  128. {
  129. .desc = "RGB 565",
  130. .pixelformat = V4L2_PIX_FMT_RGB565,
  131. .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_LE,
  132. .bpp = 16,
  133. .dlen = 8,
  134. },
  135. {
  136. .desc = "RGB 444",
  137. .pixelformat = V4L2_PIX_FMT_RGB444,
  138. .mbus_code = V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE,
  139. .bpp = 16,
  140. .dlen = 8,
  141. },
  142. };
  143. #define BCAP_MAX_FMTS ARRAY_SIZE(bcap_formats)
  144. static irqreturn_t bcap_isr(int irq, void *dev_id);
  145. static struct bcap_buffer *to_bcap_vb(struct vb2_buffer *vb)
  146. {
  147. return container_of(vb, struct bcap_buffer, vb);
  148. }
  149. static int bcap_init_sensor_formats(struct bcap_device *bcap_dev)
  150. {
  151. enum v4l2_mbus_pixelcode code;
  152. struct bcap_format *sf;
  153. unsigned int num_formats = 0;
  154. int i, j;
  155. while (!v4l2_subdev_call(bcap_dev->sd, video,
  156. enum_mbus_fmt, num_formats, &code))
  157. num_formats++;
  158. if (!num_formats)
  159. return -ENXIO;
  160. sf = kzalloc(num_formats * sizeof(*sf), GFP_KERNEL);
  161. if (!sf)
  162. return -ENOMEM;
  163. for (i = 0; i < num_formats; i++) {
  164. v4l2_subdev_call(bcap_dev->sd, video,
  165. enum_mbus_fmt, i, &code);
  166. for (j = 0; j < BCAP_MAX_FMTS; j++)
  167. if (code == bcap_formats[j].mbus_code)
  168. break;
  169. if (j == BCAP_MAX_FMTS) {
  170. /* we don't allow this sensor working with our bridge */
  171. kfree(sf);
  172. return -EINVAL;
  173. }
  174. sf[i] = bcap_formats[j];
  175. }
  176. bcap_dev->sensor_formats = sf;
  177. bcap_dev->num_sensor_formats = num_formats;
  178. return 0;
  179. }
  180. static void bcap_free_sensor_formats(struct bcap_device *bcap_dev)
  181. {
  182. bcap_dev->num_sensor_formats = 0;
  183. kfree(bcap_dev->sensor_formats);
  184. bcap_dev->sensor_formats = NULL;
  185. }
  186. static int bcap_open(struct file *file)
  187. {
  188. struct bcap_device *bcap_dev = video_drvdata(file);
  189. struct video_device *vfd = bcap_dev->video_dev;
  190. struct bcap_fh *bcap_fh;
  191. if (!bcap_dev->sd) {
  192. v4l2_err(&bcap_dev->v4l2_dev, "No sub device registered\n");
  193. return -ENODEV;
  194. }
  195. bcap_fh = kzalloc(sizeof(*bcap_fh), GFP_KERNEL);
  196. if (!bcap_fh) {
  197. v4l2_err(&bcap_dev->v4l2_dev,
  198. "unable to allocate memory for file handle object\n");
  199. return -ENOMEM;
  200. }
  201. v4l2_fh_init(&bcap_fh->fh, vfd);
  202. /* store pointer to v4l2_fh in private_data member of file */
  203. file->private_data = &bcap_fh->fh;
  204. v4l2_fh_add(&bcap_fh->fh);
  205. bcap_fh->io_allowed = false;
  206. return 0;
  207. }
  208. static int bcap_release(struct file *file)
  209. {
  210. struct bcap_device *bcap_dev = video_drvdata(file);
  211. struct v4l2_fh *fh = file->private_data;
  212. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  213. /* if this instance is doing IO */
  214. if (bcap_fh->io_allowed)
  215. vb2_queue_release(&bcap_dev->buffer_queue);
  216. file->private_data = NULL;
  217. v4l2_fh_del(&bcap_fh->fh);
  218. v4l2_fh_exit(&bcap_fh->fh);
  219. kfree(bcap_fh);
  220. return 0;
  221. }
  222. static int bcap_mmap(struct file *file, struct vm_area_struct *vma)
  223. {
  224. struct bcap_device *bcap_dev = video_drvdata(file);
  225. int ret;
  226. if (mutex_lock_interruptible(&bcap_dev->mutex))
  227. return -ERESTARTSYS;
  228. ret = vb2_mmap(&bcap_dev->buffer_queue, vma);
  229. mutex_unlock(&bcap_dev->mutex);
  230. return ret;
  231. }
  232. #ifndef CONFIG_MMU
  233. static unsigned long bcap_get_unmapped_area(struct file *file,
  234. unsigned long addr,
  235. unsigned long len,
  236. unsigned long pgoff,
  237. unsigned long flags)
  238. {
  239. struct bcap_device *bcap_dev = video_drvdata(file);
  240. return vb2_get_unmapped_area(&bcap_dev->buffer_queue,
  241. addr,
  242. len,
  243. pgoff,
  244. flags);
  245. }
  246. #endif
  247. static unsigned int bcap_poll(struct file *file, poll_table *wait)
  248. {
  249. struct bcap_device *bcap_dev = video_drvdata(file);
  250. unsigned int res;
  251. mutex_lock(&bcap_dev->mutex);
  252. res = vb2_poll(&bcap_dev->buffer_queue, file, wait);
  253. mutex_unlock(&bcap_dev->mutex);
  254. return res;
  255. }
  256. static int bcap_queue_setup(struct vb2_queue *vq,
  257. const struct v4l2_format *fmt,
  258. unsigned int *nbuffers, unsigned int *nplanes,
  259. unsigned int sizes[], void *alloc_ctxs[])
  260. {
  261. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  262. if (*nbuffers < BCAP_MIN_NUM_BUF)
  263. *nbuffers = BCAP_MIN_NUM_BUF;
  264. *nplanes = 1;
  265. sizes[0] = bcap_dev->fmt.sizeimage;
  266. alloc_ctxs[0] = bcap_dev->alloc_ctx;
  267. return 0;
  268. }
  269. static int bcap_buffer_init(struct vb2_buffer *vb)
  270. {
  271. struct bcap_buffer *buf = to_bcap_vb(vb);
  272. INIT_LIST_HEAD(&buf->list);
  273. return 0;
  274. }
  275. static int bcap_buffer_prepare(struct vb2_buffer *vb)
  276. {
  277. struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
  278. struct bcap_buffer *buf = to_bcap_vb(vb);
  279. unsigned long size;
  280. size = bcap_dev->fmt.sizeimage;
  281. if (vb2_plane_size(vb, 0) < size) {
  282. v4l2_err(&bcap_dev->v4l2_dev, "buffer too small (%lu < %lu)\n",
  283. vb2_plane_size(vb, 0), size);
  284. return -EINVAL;
  285. }
  286. vb2_set_plane_payload(&buf->vb, 0, size);
  287. return 0;
  288. }
  289. static void bcap_buffer_queue(struct vb2_buffer *vb)
  290. {
  291. struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
  292. struct bcap_buffer *buf = to_bcap_vb(vb);
  293. unsigned long flags;
  294. spin_lock_irqsave(&bcap_dev->lock, flags);
  295. list_add_tail(&buf->list, &bcap_dev->dma_queue);
  296. spin_unlock_irqrestore(&bcap_dev->lock, flags);
  297. }
  298. static void bcap_buffer_cleanup(struct vb2_buffer *vb)
  299. {
  300. struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
  301. struct bcap_buffer *buf = to_bcap_vb(vb);
  302. unsigned long flags;
  303. spin_lock_irqsave(&bcap_dev->lock, flags);
  304. list_del_init(&buf->list);
  305. spin_unlock_irqrestore(&bcap_dev->lock, flags);
  306. }
  307. static void bcap_lock(struct vb2_queue *vq)
  308. {
  309. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  310. mutex_lock(&bcap_dev->mutex);
  311. }
  312. static void bcap_unlock(struct vb2_queue *vq)
  313. {
  314. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  315. mutex_unlock(&bcap_dev->mutex);
  316. }
  317. static int bcap_start_streaming(struct vb2_queue *vq, unsigned int count)
  318. {
  319. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  320. struct ppi_if *ppi = bcap_dev->ppi;
  321. struct ppi_params params;
  322. int ret;
  323. /* enable streamon on the sub device */
  324. ret = v4l2_subdev_call(bcap_dev->sd, video, s_stream, 1);
  325. if (ret && (ret != -ENOIOCTLCMD)) {
  326. v4l2_err(&bcap_dev->v4l2_dev, "stream on failed in subdev\n");
  327. return ret;
  328. }
  329. /* set ppi params */
  330. params.width = bcap_dev->fmt.width;
  331. params.height = bcap_dev->fmt.height;
  332. params.bpp = bcap_dev->bpp;
  333. params.dlen = bcap_dev->dlen;
  334. params.ppi_control = bcap_dev->cfg->ppi_control;
  335. params.int_mask = bcap_dev->cfg->int_mask;
  336. if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
  337. & V4L2_IN_CAP_DV_TIMINGS) {
  338. struct v4l2_bt_timings *bt = &bcap_dev->dv_timings.bt;
  339. params.hdelay = bt->hsync + bt->hbackporch;
  340. params.vdelay = bt->vsync + bt->vbackporch;
  341. params.line = bt->hfrontporch + bt->hsync
  342. + bt->hbackporch + bt->width;
  343. params.frame = bt->vfrontporch + bt->vsync
  344. + bt->vbackporch + bt->height;
  345. if (bt->interlaced)
  346. params.frame += bt->il_vfrontporch + bt->il_vsync
  347. + bt->il_vbackporch;
  348. } else if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
  349. & V4L2_IN_CAP_STD) {
  350. params.hdelay = 0;
  351. params.vdelay = 0;
  352. if (bcap_dev->std & V4L2_STD_525_60) {
  353. params.line = 858;
  354. params.frame = 525;
  355. } else {
  356. params.line = 864;
  357. params.frame = 625;
  358. }
  359. } else {
  360. params.hdelay = 0;
  361. params.vdelay = 0;
  362. params.line = params.width + bcap_dev->cfg->blank_pixels;
  363. params.frame = params.height;
  364. }
  365. ret = ppi->ops->set_params(ppi, &params);
  366. if (ret < 0) {
  367. v4l2_err(&bcap_dev->v4l2_dev,
  368. "Error in setting ppi params\n");
  369. return ret;
  370. }
  371. /* attach ppi DMA irq handler */
  372. ret = ppi->ops->attach_irq(ppi, bcap_isr);
  373. if (ret < 0) {
  374. v4l2_err(&bcap_dev->v4l2_dev,
  375. "Error in attaching interrupt handler\n");
  376. return ret;
  377. }
  378. INIT_COMPLETION(bcap_dev->comp);
  379. bcap_dev->stop = false;
  380. return 0;
  381. }
  382. static int bcap_stop_streaming(struct vb2_queue *vq)
  383. {
  384. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  385. struct ppi_if *ppi = bcap_dev->ppi;
  386. int ret;
  387. if (!vb2_is_streaming(vq))
  388. return 0;
  389. bcap_dev->stop = true;
  390. wait_for_completion(&bcap_dev->comp);
  391. ppi->ops->stop(ppi);
  392. ppi->ops->detach_irq(ppi);
  393. ret = v4l2_subdev_call(bcap_dev->sd, video, s_stream, 0);
  394. if (ret && (ret != -ENOIOCTLCMD))
  395. v4l2_err(&bcap_dev->v4l2_dev,
  396. "stream off failed in subdev\n");
  397. /* release all active buffers */
  398. while (!list_empty(&bcap_dev->dma_queue)) {
  399. bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
  400. struct bcap_buffer, list);
  401. list_del(&bcap_dev->cur_frm->list);
  402. vb2_buffer_done(&bcap_dev->cur_frm->vb, VB2_BUF_STATE_ERROR);
  403. }
  404. return 0;
  405. }
  406. static struct vb2_ops bcap_video_qops = {
  407. .queue_setup = bcap_queue_setup,
  408. .buf_init = bcap_buffer_init,
  409. .buf_prepare = bcap_buffer_prepare,
  410. .buf_cleanup = bcap_buffer_cleanup,
  411. .buf_queue = bcap_buffer_queue,
  412. .wait_prepare = bcap_unlock,
  413. .wait_finish = bcap_lock,
  414. .start_streaming = bcap_start_streaming,
  415. .stop_streaming = bcap_stop_streaming,
  416. };
  417. static int bcap_reqbufs(struct file *file, void *priv,
  418. struct v4l2_requestbuffers *req_buf)
  419. {
  420. struct bcap_device *bcap_dev = video_drvdata(file);
  421. struct vb2_queue *vq = &bcap_dev->buffer_queue;
  422. struct v4l2_fh *fh = file->private_data;
  423. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  424. if (vb2_is_busy(vq))
  425. return -EBUSY;
  426. bcap_fh->io_allowed = true;
  427. return vb2_reqbufs(vq, req_buf);
  428. }
  429. static int bcap_querybuf(struct file *file, void *priv,
  430. struct v4l2_buffer *buf)
  431. {
  432. struct bcap_device *bcap_dev = video_drvdata(file);
  433. return vb2_querybuf(&bcap_dev->buffer_queue, buf);
  434. }
  435. static int bcap_qbuf(struct file *file, void *priv,
  436. struct v4l2_buffer *buf)
  437. {
  438. struct bcap_device *bcap_dev = video_drvdata(file);
  439. struct v4l2_fh *fh = file->private_data;
  440. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  441. if (!bcap_fh->io_allowed)
  442. return -EBUSY;
  443. return vb2_qbuf(&bcap_dev->buffer_queue, buf);
  444. }
  445. static int bcap_dqbuf(struct file *file, void *priv,
  446. struct v4l2_buffer *buf)
  447. {
  448. struct bcap_device *bcap_dev = video_drvdata(file);
  449. struct v4l2_fh *fh = file->private_data;
  450. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  451. if (!bcap_fh->io_allowed)
  452. return -EBUSY;
  453. return vb2_dqbuf(&bcap_dev->buffer_queue,
  454. buf, file->f_flags & O_NONBLOCK);
  455. }
  456. static irqreturn_t bcap_isr(int irq, void *dev_id)
  457. {
  458. struct ppi_if *ppi = dev_id;
  459. struct bcap_device *bcap_dev = ppi->priv;
  460. struct vb2_buffer *vb = &bcap_dev->cur_frm->vb;
  461. dma_addr_t addr;
  462. spin_lock(&bcap_dev->lock);
  463. if (!list_empty(&bcap_dev->dma_queue)) {
  464. v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
  465. if (ppi->err) {
  466. vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
  467. ppi->err = false;
  468. } else {
  469. vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
  470. }
  471. bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
  472. struct bcap_buffer, list);
  473. list_del(&bcap_dev->cur_frm->list);
  474. } else {
  475. /* clear error flag, we will get a new frame */
  476. if (ppi->err)
  477. ppi->err = false;
  478. }
  479. ppi->ops->stop(ppi);
  480. if (bcap_dev->stop) {
  481. complete(&bcap_dev->comp);
  482. } else {
  483. addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
  484. ppi->ops->update_addr(ppi, (unsigned long)addr);
  485. ppi->ops->start(ppi);
  486. }
  487. spin_unlock(&bcap_dev->lock);
  488. return IRQ_HANDLED;
  489. }
  490. static int bcap_streamon(struct file *file, void *priv,
  491. enum v4l2_buf_type buf_type)
  492. {
  493. struct bcap_device *bcap_dev = video_drvdata(file);
  494. struct bcap_fh *fh = file->private_data;
  495. struct ppi_if *ppi = bcap_dev->ppi;
  496. dma_addr_t addr;
  497. int ret;
  498. if (!fh->io_allowed)
  499. return -EBUSY;
  500. /* call streamon to start streaming in videobuf */
  501. ret = vb2_streamon(&bcap_dev->buffer_queue, buf_type);
  502. if (ret)
  503. return ret;
  504. /* if dma queue is empty, return error */
  505. if (list_empty(&bcap_dev->dma_queue)) {
  506. v4l2_err(&bcap_dev->v4l2_dev, "dma queue is empty\n");
  507. ret = -EINVAL;
  508. goto err;
  509. }
  510. /* get the next frame from the dma queue */
  511. bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
  512. struct bcap_buffer, list);
  513. /* remove buffer from the dma queue */
  514. list_del(&bcap_dev->cur_frm->list);
  515. addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
  516. /* update DMA address */
  517. ppi->ops->update_addr(ppi, (unsigned long)addr);
  518. /* enable ppi */
  519. ppi->ops->start(ppi);
  520. return 0;
  521. err:
  522. vb2_streamoff(&bcap_dev->buffer_queue, buf_type);
  523. return ret;
  524. }
  525. static int bcap_streamoff(struct file *file, void *priv,
  526. enum v4l2_buf_type buf_type)
  527. {
  528. struct bcap_device *bcap_dev = video_drvdata(file);
  529. struct bcap_fh *fh = file->private_data;
  530. if (!fh->io_allowed)
  531. return -EBUSY;
  532. return vb2_streamoff(&bcap_dev->buffer_queue, buf_type);
  533. }
  534. static int bcap_querystd(struct file *file, void *priv, v4l2_std_id *std)
  535. {
  536. struct bcap_device *bcap_dev = video_drvdata(file);
  537. return v4l2_subdev_call(bcap_dev->sd, video, querystd, std);
  538. }
  539. static int bcap_g_std(struct file *file, void *priv, v4l2_std_id *std)
  540. {
  541. struct bcap_device *bcap_dev = video_drvdata(file);
  542. *std = bcap_dev->std;
  543. return 0;
  544. }
  545. static int bcap_s_std(struct file *file, void *priv, v4l2_std_id std)
  546. {
  547. struct bcap_device *bcap_dev = video_drvdata(file);
  548. int ret;
  549. if (vb2_is_busy(&bcap_dev->buffer_queue))
  550. return -EBUSY;
  551. ret = v4l2_subdev_call(bcap_dev->sd, core, s_std, std);
  552. if (ret < 0)
  553. return ret;
  554. bcap_dev->std = std;
  555. return 0;
  556. }
  557. static int bcap_enum_dv_timings(struct file *file, void *priv,
  558. struct v4l2_enum_dv_timings *timings)
  559. {
  560. struct bcap_device *bcap_dev = video_drvdata(file);
  561. return v4l2_subdev_call(bcap_dev->sd, video,
  562. enum_dv_timings, timings);
  563. }
  564. static int bcap_query_dv_timings(struct file *file, void *priv,
  565. struct v4l2_dv_timings *timings)
  566. {
  567. struct bcap_device *bcap_dev = video_drvdata(file);
  568. return v4l2_subdev_call(bcap_dev->sd, video,
  569. query_dv_timings, timings);
  570. }
  571. static int bcap_g_dv_timings(struct file *file, void *priv,
  572. struct v4l2_dv_timings *timings)
  573. {
  574. struct bcap_device *bcap_dev = video_drvdata(file);
  575. *timings = bcap_dev->dv_timings;
  576. return 0;
  577. }
  578. static int bcap_s_dv_timings(struct file *file, void *priv,
  579. struct v4l2_dv_timings *timings)
  580. {
  581. struct bcap_device *bcap_dev = video_drvdata(file);
  582. int ret;
  583. if (vb2_is_busy(&bcap_dev->buffer_queue))
  584. return -EBUSY;
  585. ret = v4l2_subdev_call(bcap_dev->sd, video, s_dv_timings, timings);
  586. if (ret < 0)
  587. return ret;
  588. bcap_dev->dv_timings = *timings;
  589. return 0;
  590. }
  591. static int bcap_enum_input(struct file *file, void *priv,
  592. struct v4l2_input *input)
  593. {
  594. struct bcap_device *bcap_dev = video_drvdata(file);
  595. struct bfin_capture_config *config = bcap_dev->cfg;
  596. int ret;
  597. u32 status;
  598. if (input->index >= config->num_inputs)
  599. return -EINVAL;
  600. *input = config->inputs[input->index];
  601. /* get input status */
  602. ret = v4l2_subdev_call(bcap_dev->sd, video, g_input_status, &status);
  603. if (!ret)
  604. input->status = status;
  605. return 0;
  606. }
  607. static int bcap_g_input(struct file *file, void *priv, unsigned int *index)
  608. {
  609. struct bcap_device *bcap_dev = video_drvdata(file);
  610. *index = bcap_dev->cur_input;
  611. return 0;
  612. }
  613. static int bcap_s_input(struct file *file, void *priv, unsigned int index)
  614. {
  615. struct bcap_device *bcap_dev = video_drvdata(file);
  616. struct bfin_capture_config *config = bcap_dev->cfg;
  617. struct bcap_route *route;
  618. int ret;
  619. if (vb2_is_busy(&bcap_dev->buffer_queue))
  620. return -EBUSY;
  621. if (index >= config->num_inputs)
  622. return -EINVAL;
  623. route = &config->routes[index];
  624. ret = v4l2_subdev_call(bcap_dev->sd, video, s_routing,
  625. route->input, route->output, 0);
  626. if ((ret < 0) && (ret != -ENOIOCTLCMD)) {
  627. v4l2_err(&bcap_dev->v4l2_dev, "Failed to set input\n");
  628. return ret;
  629. }
  630. bcap_dev->cur_input = index;
  631. /* if this route has specific config, update ppi control */
  632. if (route->ppi_control)
  633. config->ppi_control = route->ppi_control;
  634. return 0;
  635. }
  636. static int bcap_try_format(struct bcap_device *bcap,
  637. struct v4l2_pix_format *pixfmt,
  638. struct bcap_format *bcap_fmt)
  639. {
  640. struct bcap_format *sf = bcap->sensor_formats;
  641. struct bcap_format *fmt = NULL;
  642. struct v4l2_mbus_framefmt mbus_fmt;
  643. int ret, i;
  644. for (i = 0; i < bcap->num_sensor_formats; i++) {
  645. fmt = &sf[i];
  646. if (pixfmt->pixelformat == fmt->pixelformat)
  647. break;
  648. }
  649. if (i == bcap->num_sensor_formats)
  650. fmt = &sf[0];
  651. v4l2_fill_mbus_format(&mbus_fmt, pixfmt, fmt->mbus_code);
  652. ret = v4l2_subdev_call(bcap->sd, video,
  653. try_mbus_fmt, &mbus_fmt);
  654. if (ret < 0)
  655. return ret;
  656. v4l2_fill_pix_format(pixfmt, &mbus_fmt);
  657. if (bcap_fmt) {
  658. for (i = 0; i < bcap->num_sensor_formats; i++) {
  659. fmt = &sf[i];
  660. if (mbus_fmt.code == fmt->mbus_code)
  661. break;
  662. }
  663. *bcap_fmt = *fmt;
  664. }
  665. pixfmt->bytesperline = pixfmt->width * fmt->bpp / 8;
  666. pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
  667. return 0;
  668. }
  669. static int bcap_enum_fmt_vid_cap(struct file *file, void *priv,
  670. struct v4l2_fmtdesc *fmt)
  671. {
  672. struct bcap_device *bcap_dev = video_drvdata(file);
  673. struct bcap_format *sf = bcap_dev->sensor_formats;
  674. if (fmt->index >= bcap_dev->num_sensor_formats)
  675. return -EINVAL;
  676. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  677. strlcpy(fmt->description,
  678. sf[fmt->index].desc,
  679. sizeof(fmt->description));
  680. fmt->pixelformat = sf[fmt->index].pixelformat;
  681. return 0;
  682. }
  683. static int bcap_try_fmt_vid_cap(struct file *file, void *priv,
  684. struct v4l2_format *fmt)
  685. {
  686. struct bcap_device *bcap_dev = video_drvdata(file);
  687. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  688. return bcap_try_format(bcap_dev, pixfmt, NULL);
  689. }
  690. static int bcap_g_fmt_vid_cap(struct file *file, void *priv,
  691. struct v4l2_format *fmt)
  692. {
  693. struct bcap_device *bcap_dev = video_drvdata(file);
  694. fmt->fmt.pix = bcap_dev->fmt;
  695. return 0;
  696. }
  697. static int bcap_s_fmt_vid_cap(struct file *file, void *priv,
  698. struct v4l2_format *fmt)
  699. {
  700. struct bcap_device *bcap_dev = video_drvdata(file);
  701. struct v4l2_mbus_framefmt mbus_fmt;
  702. struct bcap_format bcap_fmt;
  703. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  704. int ret;
  705. if (vb2_is_busy(&bcap_dev->buffer_queue))
  706. return -EBUSY;
  707. /* see if format works */
  708. ret = bcap_try_format(bcap_dev, pixfmt, &bcap_fmt);
  709. if (ret < 0)
  710. return ret;
  711. v4l2_fill_mbus_format(&mbus_fmt, pixfmt, bcap_fmt.mbus_code);
  712. ret = v4l2_subdev_call(bcap_dev->sd, video, s_mbus_fmt, &mbus_fmt);
  713. if (ret < 0)
  714. return ret;
  715. bcap_dev->fmt = *pixfmt;
  716. bcap_dev->bpp = bcap_fmt.bpp;
  717. bcap_dev->dlen = bcap_fmt.dlen;
  718. return 0;
  719. }
  720. static int bcap_querycap(struct file *file, void *priv,
  721. struct v4l2_capability *cap)
  722. {
  723. struct bcap_device *bcap_dev = video_drvdata(file);
  724. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  725. strlcpy(cap->driver, CAPTURE_DRV_NAME, sizeof(cap->driver));
  726. strlcpy(cap->bus_info, "Blackfin Platform", sizeof(cap->bus_info));
  727. strlcpy(cap->card, bcap_dev->cfg->card_name, sizeof(cap->card));
  728. return 0;
  729. }
  730. static int bcap_g_parm(struct file *file, void *fh,
  731. struct v4l2_streamparm *a)
  732. {
  733. struct bcap_device *bcap_dev = video_drvdata(file);
  734. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  735. return -EINVAL;
  736. return v4l2_subdev_call(bcap_dev->sd, video, g_parm, a);
  737. }
  738. static int bcap_s_parm(struct file *file, void *fh,
  739. struct v4l2_streamparm *a)
  740. {
  741. struct bcap_device *bcap_dev = video_drvdata(file);
  742. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  743. return -EINVAL;
  744. return v4l2_subdev_call(bcap_dev->sd, video, s_parm, a);
  745. }
  746. static int bcap_g_chip_ident(struct file *file, void *priv,
  747. struct v4l2_dbg_chip_ident *chip)
  748. {
  749. struct bcap_device *bcap_dev = video_drvdata(file);
  750. chip->ident = V4L2_IDENT_NONE;
  751. chip->revision = 0;
  752. if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
  753. chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
  754. return -EINVAL;
  755. return v4l2_subdev_call(bcap_dev->sd, core,
  756. g_chip_ident, chip);
  757. }
  758. #ifdef CONFIG_VIDEO_ADV_DEBUG
  759. static int bcap_dbg_g_register(struct file *file, void *priv,
  760. struct v4l2_dbg_register *reg)
  761. {
  762. struct bcap_device *bcap_dev = video_drvdata(file);
  763. return v4l2_subdev_call(bcap_dev->sd, core,
  764. g_register, reg);
  765. }
  766. static int bcap_dbg_s_register(struct file *file, void *priv,
  767. const struct v4l2_dbg_register *reg)
  768. {
  769. struct bcap_device *bcap_dev = video_drvdata(file);
  770. return v4l2_subdev_call(bcap_dev->sd, core,
  771. s_register, reg);
  772. }
  773. #endif
  774. static int bcap_log_status(struct file *file, void *priv)
  775. {
  776. struct bcap_device *bcap_dev = video_drvdata(file);
  777. /* status for sub devices */
  778. v4l2_device_call_all(&bcap_dev->v4l2_dev, 0, core, log_status);
  779. return 0;
  780. }
  781. static const struct v4l2_ioctl_ops bcap_ioctl_ops = {
  782. .vidioc_querycap = bcap_querycap,
  783. .vidioc_g_fmt_vid_cap = bcap_g_fmt_vid_cap,
  784. .vidioc_enum_fmt_vid_cap = bcap_enum_fmt_vid_cap,
  785. .vidioc_s_fmt_vid_cap = bcap_s_fmt_vid_cap,
  786. .vidioc_try_fmt_vid_cap = bcap_try_fmt_vid_cap,
  787. .vidioc_enum_input = bcap_enum_input,
  788. .vidioc_g_input = bcap_g_input,
  789. .vidioc_s_input = bcap_s_input,
  790. .vidioc_querystd = bcap_querystd,
  791. .vidioc_s_std = bcap_s_std,
  792. .vidioc_g_std = bcap_g_std,
  793. .vidioc_s_dv_timings = bcap_s_dv_timings,
  794. .vidioc_g_dv_timings = bcap_g_dv_timings,
  795. .vidioc_query_dv_timings = bcap_query_dv_timings,
  796. .vidioc_enum_dv_timings = bcap_enum_dv_timings,
  797. .vidioc_reqbufs = bcap_reqbufs,
  798. .vidioc_querybuf = bcap_querybuf,
  799. .vidioc_qbuf = bcap_qbuf,
  800. .vidioc_dqbuf = bcap_dqbuf,
  801. .vidioc_streamon = bcap_streamon,
  802. .vidioc_streamoff = bcap_streamoff,
  803. .vidioc_g_parm = bcap_g_parm,
  804. .vidioc_s_parm = bcap_s_parm,
  805. .vidioc_g_chip_ident = bcap_g_chip_ident,
  806. #ifdef CONFIG_VIDEO_ADV_DEBUG
  807. .vidioc_g_register = bcap_dbg_g_register,
  808. .vidioc_s_register = bcap_dbg_s_register,
  809. #endif
  810. .vidioc_log_status = bcap_log_status,
  811. };
  812. static struct v4l2_file_operations bcap_fops = {
  813. .owner = THIS_MODULE,
  814. .open = bcap_open,
  815. .release = bcap_release,
  816. .unlocked_ioctl = video_ioctl2,
  817. .mmap = bcap_mmap,
  818. #ifndef CONFIG_MMU
  819. .get_unmapped_area = bcap_get_unmapped_area,
  820. #endif
  821. .poll = bcap_poll
  822. };
  823. static int bcap_probe(struct platform_device *pdev)
  824. {
  825. struct bcap_device *bcap_dev;
  826. struct video_device *vfd;
  827. struct i2c_adapter *i2c_adap;
  828. struct bfin_capture_config *config;
  829. struct vb2_queue *q;
  830. struct bcap_route *route;
  831. int ret;
  832. config = pdev->dev.platform_data;
  833. if (!config || !config->num_inputs) {
  834. v4l2_err(pdev->dev.driver, "Unable to get board config\n");
  835. return -ENODEV;
  836. }
  837. bcap_dev = kzalloc(sizeof(*bcap_dev), GFP_KERNEL);
  838. if (!bcap_dev) {
  839. v4l2_err(pdev->dev.driver, "Unable to alloc bcap_dev\n");
  840. return -ENOMEM;
  841. }
  842. bcap_dev->cfg = config;
  843. bcap_dev->ppi = ppi_create_instance(config->ppi_info);
  844. if (!bcap_dev->ppi) {
  845. v4l2_err(pdev->dev.driver, "Unable to create ppi\n");
  846. ret = -ENODEV;
  847. goto err_free_dev;
  848. }
  849. bcap_dev->ppi->priv = bcap_dev;
  850. bcap_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  851. if (IS_ERR(bcap_dev->alloc_ctx)) {
  852. ret = PTR_ERR(bcap_dev->alloc_ctx);
  853. goto err_free_ppi;
  854. }
  855. vfd = video_device_alloc();
  856. if (!vfd) {
  857. ret = -ENOMEM;
  858. v4l2_err(pdev->dev.driver, "Unable to alloc video device\n");
  859. goto err_cleanup_ctx;
  860. }
  861. /* initialize field of video device */
  862. vfd->release = video_device_release;
  863. vfd->fops = &bcap_fops;
  864. vfd->ioctl_ops = &bcap_ioctl_ops;
  865. vfd->tvnorms = 0;
  866. vfd->v4l2_dev = &bcap_dev->v4l2_dev;
  867. set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  868. strncpy(vfd->name, CAPTURE_DRV_NAME, sizeof(vfd->name));
  869. bcap_dev->video_dev = vfd;
  870. ret = v4l2_device_register(&pdev->dev, &bcap_dev->v4l2_dev);
  871. if (ret) {
  872. v4l2_err(pdev->dev.driver,
  873. "Unable to register v4l2 device\n");
  874. goto err_release_vdev;
  875. }
  876. v4l2_info(&bcap_dev->v4l2_dev, "v4l2 device registered\n");
  877. bcap_dev->v4l2_dev.ctrl_handler = &bcap_dev->ctrl_handler;
  878. ret = v4l2_ctrl_handler_init(&bcap_dev->ctrl_handler, 0);
  879. if (ret) {
  880. v4l2_err(&bcap_dev->v4l2_dev,
  881. "Unable to init control handler\n");
  882. goto err_unreg_v4l2;
  883. }
  884. spin_lock_init(&bcap_dev->lock);
  885. /* initialize queue */
  886. q = &bcap_dev->buffer_queue;
  887. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  888. q->io_modes = VB2_MMAP;
  889. q->drv_priv = bcap_dev;
  890. q->buf_struct_size = sizeof(struct bcap_buffer);
  891. q->ops = &bcap_video_qops;
  892. q->mem_ops = &vb2_dma_contig_memops;
  893. q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  894. vb2_queue_init(q);
  895. mutex_init(&bcap_dev->mutex);
  896. init_completion(&bcap_dev->comp);
  897. /* init video dma queues */
  898. INIT_LIST_HEAD(&bcap_dev->dma_queue);
  899. vfd->lock = &bcap_dev->mutex;
  900. /* register video device */
  901. ret = video_register_device(bcap_dev->video_dev, VFL_TYPE_GRABBER, -1);
  902. if (ret) {
  903. v4l2_err(&bcap_dev->v4l2_dev,
  904. "Unable to register video device\n");
  905. goto err_free_handler;
  906. }
  907. video_set_drvdata(bcap_dev->video_dev, bcap_dev);
  908. v4l2_info(&bcap_dev->v4l2_dev, "video device registered as: %s\n",
  909. video_device_node_name(vfd));
  910. /* load up the subdevice */
  911. i2c_adap = i2c_get_adapter(config->i2c_adapter_id);
  912. if (!i2c_adap) {
  913. v4l2_err(&bcap_dev->v4l2_dev,
  914. "Unable to find i2c adapter\n");
  915. ret = -ENODEV;
  916. goto err_unreg_vdev;
  917. }
  918. bcap_dev->sd = v4l2_i2c_new_subdev_board(&bcap_dev->v4l2_dev,
  919. i2c_adap,
  920. &config->board_info,
  921. NULL);
  922. if (bcap_dev->sd) {
  923. int i;
  924. /* update tvnorms from the sub devices */
  925. for (i = 0; i < config->num_inputs; i++)
  926. vfd->tvnorms |= config->inputs[i].std;
  927. } else {
  928. v4l2_err(&bcap_dev->v4l2_dev,
  929. "Unable to register sub device\n");
  930. ret = -ENODEV;
  931. goto err_unreg_vdev;
  932. }
  933. v4l2_info(&bcap_dev->v4l2_dev, "v4l2 sub device registered\n");
  934. /*
  935. * explicitly set input, otherwise some boards
  936. * may not work at the state as we expected
  937. */
  938. route = &config->routes[0];
  939. ret = v4l2_subdev_call(bcap_dev->sd, video, s_routing,
  940. route->input, route->output, 0);
  941. if ((ret < 0) && (ret != -ENOIOCTLCMD)) {
  942. v4l2_err(&bcap_dev->v4l2_dev, "Failed to set input\n");
  943. goto err_unreg_vdev;
  944. }
  945. bcap_dev->cur_input = 0;
  946. /* if this route has specific config, update ppi control */
  947. if (route->ppi_control)
  948. config->ppi_control = route->ppi_control;
  949. /* now we can probe the default state */
  950. if (config->inputs[0].capabilities & V4L2_IN_CAP_STD) {
  951. v4l2_std_id std;
  952. ret = v4l2_subdev_call(bcap_dev->sd, core, g_std, &std);
  953. if (ret) {
  954. v4l2_err(&bcap_dev->v4l2_dev,
  955. "Unable to get std\n");
  956. goto err_unreg_vdev;
  957. }
  958. bcap_dev->std = std;
  959. }
  960. if (config->inputs[0].capabilities & V4L2_IN_CAP_DV_TIMINGS) {
  961. struct v4l2_dv_timings dv_timings;
  962. ret = v4l2_subdev_call(bcap_dev->sd, video,
  963. g_dv_timings, &dv_timings);
  964. if (ret) {
  965. v4l2_err(&bcap_dev->v4l2_dev,
  966. "Unable to get dv timings\n");
  967. goto err_unreg_vdev;
  968. }
  969. bcap_dev->dv_timings = dv_timings;
  970. }
  971. ret = bcap_init_sensor_formats(bcap_dev);
  972. if (ret) {
  973. v4l2_err(&bcap_dev->v4l2_dev,
  974. "Unable to create sensor formats table\n");
  975. goto err_unreg_vdev;
  976. }
  977. return 0;
  978. err_unreg_vdev:
  979. video_unregister_device(bcap_dev->video_dev);
  980. bcap_dev->video_dev = NULL;
  981. err_free_handler:
  982. v4l2_ctrl_handler_free(&bcap_dev->ctrl_handler);
  983. err_unreg_v4l2:
  984. v4l2_device_unregister(&bcap_dev->v4l2_dev);
  985. err_release_vdev:
  986. if (bcap_dev->video_dev)
  987. video_device_release(bcap_dev->video_dev);
  988. err_cleanup_ctx:
  989. vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
  990. err_free_ppi:
  991. ppi_delete_instance(bcap_dev->ppi);
  992. err_free_dev:
  993. kfree(bcap_dev);
  994. return ret;
  995. }
  996. static int bcap_remove(struct platform_device *pdev)
  997. {
  998. struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
  999. struct bcap_device *bcap_dev = container_of(v4l2_dev,
  1000. struct bcap_device, v4l2_dev);
  1001. bcap_free_sensor_formats(bcap_dev);
  1002. video_unregister_device(bcap_dev->video_dev);
  1003. v4l2_ctrl_handler_free(&bcap_dev->ctrl_handler);
  1004. v4l2_device_unregister(v4l2_dev);
  1005. vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
  1006. ppi_delete_instance(bcap_dev->ppi);
  1007. kfree(bcap_dev);
  1008. return 0;
  1009. }
  1010. static struct platform_driver bcap_driver = {
  1011. .driver = {
  1012. .name = CAPTURE_DRV_NAME,
  1013. .owner = THIS_MODULE,
  1014. },
  1015. .probe = bcap_probe,
  1016. .remove = bcap_remove,
  1017. };
  1018. module_platform_driver(bcap_driver);
  1019. MODULE_DESCRIPTION("Analog Devices blackfin video capture driver");
  1020. MODULE_AUTHOR("Scott Jiang <Scott.Jiang.Linux@gmail.com>");
  1021. MODULE_LICENSE("GPL v2");