fimc-isp-video.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
  3. *
  4. * FIMC-IS ISP video input and video output DMA interface driver
  5. *
  6. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  7. * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
  8. *
  9. * The hardware handling code derived from a driver written by
  10. * Younghwan Joo <yhwan.joo@samsung.com>.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/bitops.h>
  17. #include <linux/device.h>
  18. #include <linux/delay.h>
  19. #include <linux/errno.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/types.h>
  23. #include <linux/printk.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/slab.h>
  26. #include <linux/videodev2.h>
  27. #include <media/v4l2-device.h>
  28. #include <media/v4l2-ioctl.h>
  29. #include <media/videobuf2-core.h>
  30. #include <media/videobuf2-dma-contig.h>
  31. #include <media/exynos-fimc.h>
  32. #include "common.h"
  33. #include "media-dev.h"
  34. #include "fimc-is.h"
  35. #include "fimc-isp-video.h"
  36. #include "fimc-is-param.h"
  37. static int isp_video_capture_queue_setup(struct vb2_queue *vq,
  38. const struct v4l2_format *pfmt,
  39. unsigned int *num_buffers, unsigned int *num_planes,
  40. unsigned int sizes[], void *allocators[])
  41. {
  42. struct fimc_isp *isp = vb2_get_drv_priv(vq);
  43. struct v4l2_pix_format_mplane *vid_fmt = &isp->video_capture.pixfmt;
  44. const struct v4l2_pix_format_mplane *pixm = NULL;
  45. const struct fimc_fmt *fmt;
  46. unsigned int wh, i;
  47. if (pfmt) {
  48. pixm = &pfmt->fmt.pix_mp;
  49. fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, -1);
  50. wh = pixm->width * pixm->height;
  51. } else {
  52. fmt = isp->video_capture.format;
  53. wh = vid_fmt->width * vid_fmt->height;
  54. }
  55. if (fmt == NULL)
  56. return -EINVAL;
  57. *num_buffers = clamp_t(u32, *num_buffers, FIMC_ISP_REQ_BUFS_MIN,
  58. FIMC_ISP_REQ_BUFS_MAX);
  59. *num_planes = fmt->memplanes;
  60. for (i = 0; i < fmt->memplanes; i++) {
  61. unsigned int size = (wh * fmt->depth[i]) / 8;
  62. if (pixm)
  63. sizes[i] = max(size, pixm->plane_fmt[i].sizeimage);
  64. else
  65. sizes[i] = size;
  66. allocators[i] = isp->alloc_ctx;
  67. }
  68. return 0;
  69. }
  70. static inline struct param_dma_output *__get_isp_dma2(struct fimc_is *is)
  71. {
  72. return &__get_curr_is_config(is)->isp.dma2_output;
  73. }
  74. static int isp_video_capture_start_streaming(struct vb2_queue *q,
  75. unsigned int count)
  76. {
  77. struct fimc_isp *isp = vb2_get_drv_priv(q);
  78. struct fimc_is *is = fimc_isp_to_is(isp);
  79. struct param_dma_output *dma = __get_isp_dma2(is);
  80. struct fimc_is_video *video = &isp->video_capture;
  81. int ret;
  82. if (!test_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state) ||
  83. test_bit(ST_ISP_VID_CAP_STREAMING, &isp->state))
  84. return 0;
  85. dma->cmd = DMA_OUTPUT_COMMAND_ENABLE;
  86. dma->notify_dma_done = DMA_OUTPUT_NOTIFY_DMA_DONE_ENABLE;
  87. dma->buffer_address = is->is_dma_p_region +
  88. DMA2_OUTPUT_ADDR_ARRAY_OFFS;
  89. dma->buffer_number = video->reqbufs_count;
  90. dma->dma_out_mask = video->buf_mask;
  91. isp_dbg(2, &video->ve.vdev,
  92. "buf_count: %d, planes: %d, dma addr table: %#x\n",
  93. video->buf_count, video->format->memplanes,
  94. dma->buffer_address);
  95. fimc_is_mem_barrier();
  96. fimc_is_set_param_bit(is, PARAM_ISP_DMA2_OUTPUT);
  97. __fimc_is_hw_update_param(is, PARAM_ISP_DMA2_OUTPUT);
  98. ret = fimc_is_itf_s_param(is, false);
  99. if (ret < 0)
  100. return ret;
  101. ret = fimc_pipeline_call(&video->ve, set_stream, 1);
  102. if (ret < 0)
  103. return ret;
  104. set_bit(ST_ISP_VID_CAP_STREAMING, &isp->state);
  105. return ret;
  106. }
  107. static void isp_video_capture_stop_streaming(struct vb2_queue *q)
  108. {
  109. struct fimc_isp *isp = vb2_get_drv_priv(q);
  110. struct fimc_is *is = fimc_isp_to_is(isp);
  111. struct param_dma_output *dma = __get_isp_dma2(is);
  112. int ret;
  113. ret = fimc_pipeline_call(&isp->video_capture.ve, set_stream, 0);
  114. if (ret < 0)
  115. return;
  116. dma->cmd = DMA_OUTPUT_COMMAND_DISABLE;
  117. dma->notify_dma_done = DMA_OUTPUT_NOTIFY_DMA_DONE_DISABLE;
  118. dma->buffer_number = 0;
  119. dma->buffer_address = 0;
  120. dma->dma_out_mask = 0;
  121. fimc_is_set_param_bit(is, PARAM_ISP_DMA2_OUTPUT);
  122. __fimc_is_hw_update_param(is, PARAM_ISP_DMA2_OUTPUT);
  123. ret = fimc_is_itf_s_param(is, false);
  124. if (ret < 0)
  125. dev_warn(&is->pdev->dev, "%s: DMA stop failed\n", __func__);
  126. fimc_is_hw_set_isp_buf_mask(is, 0);
  127. clear_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state);
  128. clear_bit(ST_ISP_VID_CAP_STREAMING, &isp->state);
  129. isp->video_capture.buf_count = 0;
  130. }
  131. static int isp_video_capture_buffer_prepare(struct vb2_buffer *vb)
  132. {
  133. struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2_queue);
  134. struct fimc_is_video *video = &isp->video_capture;
  135. int i;
  136. if (video->format == NULL)
  137. return -EINVAL;
  138. for (i = 0; i < video->format->memplanes; i++) {
  139. unsigned long size = video->pixfmt.plane_fmt[i].sizeimage;
  140. if (vb2_plane_size(vb, i) < size) {
  141. v4l2_err(&video->ve.vdev,
  142. "User buffer too small (%ld < %ld)\n",
  143. vb2_plane_size(vb, i), size);
  144. return -EINVAL;
  145. }
  146. vb2_set_plane_payload(vb, i, size);
  147. }
  148. /* Check if we get one of the already known buffers. */
  149. if (test_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state)) {
  150. dma_addr_t dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
  151. int i;
  152. for (i = 0; i < video->buf_count; i++)
  153. if (video->buffers[i]->dma_addr[0] == dma_addr)
  154. return 0;
  155. return -ENXIO;
  156. }
  157. return 0;
  158. }
  159. static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
  160. {
  161. struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2_queue);
  162. struct fimc_is_video *video = &isp->video_capture;
  163. struct fimc_is *is = fimc_isp_to_is(isp);
  164. struct isp_video_buf *ivb = to_isp_video_buf(vb);
  165. unsigned long flags;
  166. unsigned int i;
  167. if (test_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state)) {
  168. spin_lock_irqsave(&is->slock, flags);
  169. video->buf_mask |= BIT(ivb->index);
  170. spin_unlock_irqrestore(&is->slock, flags);
  171. } else {
  172. unsigned int num_planes = video->format->memplanes;
  173. ivb->index = video->buf_count;
  174. video->buffers[ivb->index] = ivb;
  175. for (i = 0; i < num_planes; i++) {
  176. int buf_index = ivb->index * num_planes + i;
  177. ivb->dma_addr[i] = vb2_dma_contig_plane_dma_addr(vb, i);
  178. is->is_p_region->shared[32 + buf_index] =
  179. ivb->dma_addr[i];
  180. isp_dbg(2, &video->ve.vdev,
  181. "dma_buf %d (%d/%d/%d) addr: %#x\n",
  182. buf_index, ivb->index, i, vb->v4l2_buf.index,
  183. ivb->dma_addr[i]);
  184. }
  185. if (++video->buf_count < video->reqbufs_count)
  186. return;
  187. video->buf_mask = (1UL << video->buf_count) - 1;
  188. set_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state);
  189. }
  190. if (!test_bit(ST_ISP_VID_CAP_STREAMING, &isp->state))
  191. isp_video_capture_start_streaming(vb->vb2_queue, 0);
  192. }
  193. /*
  194. * FIMC-IS ISP input and output DMA interface interrupt handler.
  195. * Locking: called with is->slock spinlock held.
  196. */
  197. void fimc_isp_video_irq_handler(struct fimc_is *is)
  198. {
  199. struct fimc_is_video *video = &is->isp.video_capture;
  200. struct vb2_buffer *vb;
  201. int buf_index;
  202. /* TODO: Ensure the DMA is really stopped in stop_streaming callback */
  203. if (!test_bit(ST_ISP_VID_CAP_STREAMING, &is->isp.state))
  204. return;
  205. buf_index = (is->i2h_cmd.args[1] - 1) % video->buf_count;
  206. vb = &video->buffers[buf_index]->vb;
  207. v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
  208. vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
  209. video->buf_mask &= ~BIT(buf_index);
  210. fimc_is_hw_set_isp_buf_mask(is, video->buf_mask);
  211. }
  212. static const struct vb2_ops isp_video_capture_qops = {
  213. .queue_setup = isp_video_capture_queue_setup,
  214. .buf_prepare = isp_video_capture_buffer_prepare,
  215. .buf_queue = isp_video_capture_buffer_queue,
  216. .wait_prepare = vb2_ops_wait_prepare,
  217. .wait_finish = vb2_ops_wait_finish,
  218. .start_streaming = isp_video_capture_start_streaming,
  219. .stop_streaming = isp_video_capture_stop_streaming,
  220. };
  221. static int isp_video_open(struct file *file)
  222. {
  223. struct fimc_isp *isp = video_drvdata(file);
  224. struct exynos_video_entity *ve = &isp->video_capture.ve;
  225. struct media_entity *me = &ve->vdev.entity;
  226. int ret;
  227. if (mutex_lock_interruptible(&isp->video_lock))
  228. return -ERESTARTSYS;
  229. ret = v4l2_fh_open(file);
  230. if (ret < 0)
  231. goto unlock;
  232. ret = pm_runtime_get_sync(&isp->pdev->dev);
  233. if (ret < 0)
  234. goto rel_fh;
  235. if (v4l2_fh_is_singular_file(file)) {
  236. mutex_lock(&me->parent->graph_mutex);
  237. ret = fimc_pipeline_call(ve, open, me, true);
  238. /* Mark the video pipeline as in use. */
  239. if (ret == 0)
  240. me->use_count++;
  241. mutex_unlock(&me->parent->graph_mutex);
  242. }
  243. if (!ret)
  244. goto unlock;
  245. rel_fh:
  246. v4l2_fh_release(file);
  247. unlock:
  248. mutex_unlock(&isp->video_lock);
  249. return ret;
  250. }
  251. static int isp_video_release(struct file *file)
  252. {
  253. struct fimc_isp *isp = video_drvdata(file);
  254. struct fimc_is_video *ivc = &isp->video_capture;
  255. struct media_entity *entity = &ivc->ve.vdev.entity;
  256. struct media_device *mdev = entity->parent;
  257. int ret = 0;
  258. mutex_lock(&isp->video_lock);
  259. if (v4l2_fh_is_singular_file(file) && ivc->streaming) {
  260. media_entity_pipeline_stop(entity);
  261. ivc->streaming = 0;
  262. }
  263. vb2_fop_release(file);
  264. if (v4l2_fh_is_singular_file(file)) {
  265. fimc_pipeline_call(&ivc->ve, close);
  266. mutex_lock(&mdev->graph_mutex);
  267. entity->use_count--;
  268. mutex_unlock(&mdev->graph_mutex);
  269. }
  270. pm_runtime_put(&isp->pdev->dev);
  271. mutex_unlock(&isp->video_lock);
  272. return ret;
  273. }
  274. static const struct v4l2_file_operations isp_video_fops = {
  275. .owner = THIS_MODULE,
  276. .open = isp_video_open,
  277. .release = isp_video_release,
  278. .poll = vb2_fop_poll,
  279. .unlocked_ioctl = video_ioctl2,
  280. .mmap = vb2_fop_mmap,
  281. };
  282. /*
  283. * Video node ioctl operations
  284. */
  285. static int isp_video_querycap(struct file *file, void *priv,
  286. struct v4l2_capability *cap)
  287. {
  288. struct fimc_isp *isp = video_drvdata(file);
  289. __fimc_vidioc_querycap(&isp->pdev->dev, cap, V4L2_CAP_STREAMING);
  290. return 0;
  291. }
  292. static int isp_video_enum_fmt_mplane(struct file *file, void *priv,
  293. struct v4l2_fmtdesc *f)
  294. {
  295. const struct fimc_fmt *fmt;
  296. if (f->index >= FIMC_ISP_NUM_FORMATS)
  297. return -EINVAL;
  298. fmt = fimc_isp_find_format(NULL, NULL, f->index);
  299. if (WARN_ON(fmt == NULL))
  300. return -EINVAL;
  301. strlcpy(f->description, fmt->name, sizeof(f->description));
  302. f->pixelformat = fmt->fourcc;
  303. return 0;
  304. }
  305. static int isp_video_g_fmt_mplane(struct file *file, void *fh,
  306. struct v4l2_format *f)
  307. {
  308. struct fimc_isp *isp = video_drvdata(file);
  309. f->fmt.pix_mp = isp->video_capture.pixfmt;
  310. return 0;
  311. }
  312. static void __isp_video_try_fmt(struct fimc_isp *isp,
  313. struct v4l2_pix_format_mplane *pixm,
  314. const struct fimc_fmt **fmt)
  315. {
  316. *fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, 2);
  317. pixm->colorspace = V4L2_COLORSPACE_SRGB;
  318. pixm->field = V4L2_FIELD_NONE;
  319. pixm->num_planes = (*fmt)->memplanes;
  320. pixm->pixelformat = (*fmt)->fourcc;
  321. /*
  322. * TODO: double check with the docmentation these width/height
  323. * constraints are correct.
  324. */
  325. v4l_bound_align_image(&pixm->width, FIMC_ISP_SOURCE_WIDTH_MIN,
  326. FIMC_ISP_SOURCE_WIDTH_MAX, 3,
  327. &pixm->height, FIMC_ISP_SOURCE_HEIGHT_MIN,
  328. FIMC_ISP_SOURCE_HEIGHT_MAX, 0, 0);
  329. }
  330. static int isp_video_try_fmt_mplane(struct file *file, void *fh,
  331. struct v4l2_format *f)
  332. {
  333. struct fimc_isp *isp = video_drvdata(file);
  334. __isp_video_try_fmt(isp, &f->fmt.pix_mp, NULL);
  335. return 0;
  336. }
  337. static int isp_video_s_fmt_mplane(struct file *file, void *priv,
  338. struct v4l2_format *f)
  339. {
  340. struct fimc_isp *isp = video_drvdata(file);
  341. struct fimc_is *is = fimc_isp_to_is(isp);
  342. struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
  343. const struct fimc_fmt *ifmt = NULL;
  344. struct param_dma_output *dma = __get_isp_dma2(is);
  345. __isp_video_try_fmt(isp, pixm, &ifmt);
  346. if (WARN_ON(ifmt == NULL))
  347. return -EINVAL;
  348. dma->format = DMA_OUTPUT_FORMAT_BAYER;
  349. dma->order = DMA_OUTPUT_ORDER_GB_BG;
  350. dma->plane = ifmt->memplanes;
  351. dma->bitwidth = ifmt->depth[0];
  352. dma->width = pixm->width;
  353. dma->height = pixm->height;
  354. fimc_is_mem_barrier();
  355. isp->video_capture.format = ifmt;
  356. isp->video_capture.pixfmt = *pixm;
  357. return 0;
  358. }
  359. /*
  360. * Check for source/sink format differences at each link.
  361. * Return 0 if the formats match or -EPIPE otherwise.
  362. */
  363. static int isp_video_pipeline_validate(struct fimc_isp *isp)
  364. {
  365. struct v4l2_subdev *sd = &isp->subdev;
  366. struct v4l2_subdev_format sink_fmt, src_fmt;
  367. struct media_pad *pad;
  368. int ret;
  369. while (1) {
  370. /* Retrieve format at the sink pad */
  371. pad = &sd->entity.pads[0];
  372. if (!(pad->flags & MEDIA_PAD_FL_SINK))
  373. break;
  374. sink_fmt.pad = pad->index;
  375. sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
  376. ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sink_fmt);
  377. if (ret < 0 && ret != -ENOIOCTLCMD)
  378. return -EPIPE;
  379. /* Retrieve format at the source pad */
  380. pad = media_entity_remote_pad(pad);
  381. if (pad == NULL ||
  382. media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
  383. break;
  384. sd = media_entity_to_v4l2_subdev(pad->entity);
  385. src_fmt.pad = pad->index;
  386. src_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
  387. ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &src_fmt);
  388. if (ret < 0 && ret != -ENOIOCTLCMD)
  389. return -EPIPE;
  390. if (src_fmt.format.width != sink_fmt.format.width ||
  391. src_fmt.format.height != sink_fmt.format.height ||
  392. src_fmt.format.code != sink_fmt.format.code)
  393. return -EPIPE;
  394. }
  395. return 0;
  396. }
  397. static int isp_video_streamon(struct file *file, void *priv,
  398. enum v4l2_buf_type type)
  399. {
  400. struct fimc_isp *isp = video_drvdata(file);
  401. struct exynos_video_entity *ve = &isp->video_capture.ve;
  402. struct media_entity *me = &ve->vdev.entity;
  403. int ret;
  404. ret = media_entity_pipeline_start(me, &ve->pipe->mp);
  405. if (ret < 0)
  406. return ret;
  407. ret = isp_video_pipeline_validate(isp);
  408. if (ret < 0)
  409. goto p_stop;
  410. ret = vb2_ioctl_streamon(file, priv, type);
  411. if (ret < 0)
  412. goto p_stop;
  413. isp->video_capture.streaming = 1;
  414. return 0;
  415. p_stop:
  416. media_entity_pipeline_stop(me);
  417. return ret;
  418. }
  419. static int isp_video_streamoff(struct file *file, void *priv,
  420. enum v4l2_buf_type type)
  421. {
  422. struct fimc_isp *isp = video_drvdata(file);
  423. struct fimc_is_video *video = &isp->video_capture;
  424. int ret;
  425. ret = vb2_ioctl_streamoff(file, priv, type);
  426. if (ret < 0)
  427. return ret;
  428. media_entity_pipeline_stop(&video->ve.vdev.entity);
  429. video->streaming = 0;
  430. return 0;
  431. }
  432. static int isp_video_reqbufs(struct file *file, void *priv,
  433. struct v4l2_requestbuffers *rb)
  434. {
  435. struct fimc_isp *isp = video_drvdata(file);
  436. int ret;
  437. ret = vb2_ioctl_reqbufs(file, priv, rb);
  438. if (ret < 0)
  439. return ret;
  440. if (rb->count && rb->count < FIMC_ISP_REQ_BUFS_MIN) {
  441. rb->count = 0;
  442. vb2_ioctl_reqbufs(file, priv, rb);
  443. ret = -ENOMEM;
  444. }
  445. isp->video_capture.reqbufs_count = rb->count;
  446. return ret;
  447. }
  448. static const struct v4l2_ioctl_ops isp_video_ioctl_ops = {
  449. .vidioc_querycap = isp_video_querycap,
  450. .vidioc_enum_fmt_vid_cap_mplane = isp_video_enum_fmt_mplane,
  451. .vidioc_try_fmt_vid_cap_mplane = isp_video_try_fmt_mplane,
  452. .vidioc_s_fmt_vid_cap_mplane = isp_video_s_fmt_mplane,
  453. .vidioc_g_fmt_vid_cap_mplane = isp_video_g_fmt_mplane,
  454. .vidioc_reqbufs = isp_video_reqbufs,
  455. .vidioc_querybuf = vb2_ioctl_querybuf,
  456. .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  457. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  458. .vidioc_qbuf = vb2_ioctl_qbuf,
  459. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  460. .vidioc_streamon = isp_video_streamon,
  461. .vidioc_streamoff = isp_video_streamoff,
  462. };
  463. int fimc_isp_video_device_register(struct fimc_isp *isp,
  464. struct v4l2_device *v4l2_dev,
  465. enum v4l2_buf_type type)
  466. {
  467. struct vb2_queue *q = &isp->video_capture.vb_queue;
  468. struct fimc_is_video *iv;
  469. struct video_device *vdev;
  470. int ret;
  471. if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  472. iv = &isp->video_capture;
  473. else
  474. return -ENOSYS;
  475. mutex_init(&isp->video_lock);
  476. INIT_LIST_HEAD(&iv->pending_buf_q);
  477. INIT_LIST_HEAD(&iv->active_buf_q);
  478. iv->format = fimc_isp_find_format(NULL, NULL, 0);
  479. iv->pixfmt.width = IS_DEFAULT_WIDTH;
  480. iv->pixfmt.height = IS_DEFAULT_HEIGHT;
  481. iv->pixfmt.pixelformat = iv->format->fourcc;
  482. iv->pixfmt.colorspace = V4L2_COLORSPACE_SRGB;
  483. iv->reqbufs_count = 0;
  484. memset(q, 0, sizeof(*q));
  485. q->type = type;
  486. q->io_modes = VB2_MMAP | VB2_USERPTR;
  487. q->ops = &isp_video_capture_qops;
  488. q->mem_ops = &vb2_dma_contig_memops;
  489. q->buf_struct_size = sizeof(struct isp_video_buf);
  490. q->drv_priv = isp;
  491. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  492. q->lock = &isp->video_lock;
  493. ret = vb2_queue_init(q);
  494. if (ret < 0)
  495. return ret;
  496. vdev = &iv->ve.vdev;
  497. memset(vdev, 0, sizeof(*vdev));
  498. snprintf(vdev->name, sizeof(vdev->name), "fimc-is-isp.%s",
  499. type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ?
  500. "capture" : "output");
  501. vdev->queue = q;
  502. vdev->fops = &isp_video_fops;
  503. vdev->ioctl_ops = &isp_video_ioctl_ops;
  504. vdev->v4l2_dev = v4l2_dev;
  505. vdev->minor = -1;
  506. vdev->release = video_device_release_empty;
  507. vdev->lock = &isp->video_lock;
  508. iv->pad.flags = MEDIA_PAD_FL_SINK;
  509. ret = media_entity_init(&vdev->entity, 1, &iv->pad, 0);
  510. if (ret < 0)
  511. return ret;
  512. video_set_drvdata(vdev, isp);
  513. ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
  514. if (ret < 0) {
  515. media_entity_cleanup(&vdev->entity);
  516. return ret;
  517. }
  518. v4l2_info(v4l2_dev, "Registered %s as /dev/%s\n",
  519. vdev->name, video_device_node_name(vdev));
  520. return 0;
  521. }
  522. void fimc_isp_video_device_unregister(struct fimc_isp *isp,
  523. enum v4l2_buf_type type)
  524. {
  525. struct exynos_video_entity *ve;
  526. if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  527. ve = &isp->video_capture.ve;
  528. else
  529. return;
  530. mutex_lock(&isp->video_lock);
  531. if (video_is_registered(&ve->vdev)) {
  532. video_unregister_device(&ve->vdev);
  533. media_entity_cleanup(&ve->vdev.entity);
  534. ve->pipe = NULL;
  535. }
  536. mutex_unlock(&isp->video_lock);
  537. }