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 %pad (%d/%d/%d) addr: %pad\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. mutex_lock(&isp->video_lock);
  258. if (v4l2_fh_is_singular_file(file) && ivc->streaming) {
  259. media_entity_pipeline_stop(entity);
  260. ivc->streaming = 0;
  261. }
  262. vb2_fop_release(file);
  263. if (v4l2_fh_is_singular_file(file)) {
  264. fimc_pipeline_call(&ivc->ve, close);
  265. mutex_lock(&mdev->graph_mutex);
  266. entity->use_count--;
  267. mutex_unlock(&mdev->graph_mutex);
  268. }
  269. pm_runtime_put(&isp->pdev->dev);
  270. mutex_unlock(&isp->video_lock);
  271. return 0;
  272. }
  273. static const struct v4l2_file_operations isp_video_fops = {
  274. .owner = THIS_MODULE,
  275. .open = isp_video_open,
  276. .release = isp_video_release,
  277. .poll = vb2_fop_poll,
  278. .unlocked_ioctl = video_ioctl2,
  279. .mmap = vb2_fop_mmap,
  280. };
  281. /*
  282. * Video node ioctl operations
  283. */
  284. static int isp_video_querycap(struct file *file, void *priv,
  285. struct v4l2_capability *cap)
  286. {
  287. struct fimc_isp *isp = video_drvdata(file);
  288. __fimc_vidioc_querycap(&isp->pdev->dev, cap, V4L2_CAP_STREAMING);
  289. return 0;
  290. }
  291. static int isp_video_enum_fmt_mplane(struct file *file, void *priv,
  292. struct v4l2_fmtdesc *f)
  293. {
  294. const struct fimc_fmt *fmt;
  295. if (f->index >= FIMC_ISP_NUM_FORMATS)
  296. return -EINVAL;
  297. fmt = fimc_isp_find_format(NULL, NULL, f->index);
  298. if (WARN_ON(fmt == NULL))
  299. return -EINVAL;
  300. strlcpy(f->description, fmt->name, sizeof(f->description));
  301. f->pixelformat = fmt->fourcc;
  302. return 0;
  303. }
  304. static int isp_video_g_fmt_mplane(struct file *file, void *fh,
  305. struct v4l2_format *f)
  306. {
  307. struct fimc_isp *isp = video_drvdata(file);
  308. f->fmt.pix_mp = isp->video_capture.pixfmt;
  309. return 0;
  310. }
  311. static void __isp_video_try_fmt(struct fimc_isp *isp,
  312. struct v4l2_pix_format_mplane *pixm,
  313. const struct fimc_fmt **fmt)
  314. {
  315. *fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, 2);
  316. pixm->colorspace = V4L2_COLORSPACE_SRGB;
  317. pixm->field = V4L2_FIELD_NONE;
  318. pixm->num_planes = (*fmt)->memplanes;
  319. pixm->pixelformat = (*fmt)->fourcc;
  320. /*
  321. * TODO: double check with the docmentation these width/height
  322. * constraints are correct.
  323. */
  324. v4l_bound_align_image(&pixm->width, FIMC_ISP_SOURCE_WIDTH_MIN,
  325. FIMC_ISP_SOURCE_WIDTH_MAX, 3,
  326. &pixm->height, FIMC_ISP_SOURCE_HEIGHT_MIN,
  327. FIMC_ISP_SOURCE_HEIGHT_MAX, 0, 0);
  328. }
  329. static int isp_video_try_fmt_mplane(struct file *file, void *fh,
  330. struct v4l2_format *f)
  331. {
  332. struct fimc_isp *isp = video_drvdata(file);
  333. __isp_video_try_fmt(isp, &f->fmt.pix_mp, NULL);
  334. return 0;
  335. }
  336. static int isp_video_s_fmt_mplane(struct file *file, void *priv,
  337. struct v4l2_format *f)
  338. {
  339. struct fimc_isp *isp = video_drvdata(file);
  340. struct fimc_is *is = fimc_isp_to_is(isp);
  341. struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
  342. const struct fimc_fmt *ifmt = NULL;
  343. struct param_dma_output *dma = __get_isp_dma2(is);
  344. __isp_video_try_fmt(isp, pixm, &ifmt);
  345. if (WARN_ON(ifmt == NULL))
  346. return -EINVAL;
  347. dma->format = DMA_OUTPUT_FORMAT_BAYER;
  348. dma->order = DMA_OUTPUT_ORDER_GB_BG;
  349. dma->plane = ifmt->memplanes;
  350. dma->bitwidth = ifmt->depth[0];
  351. dma->width = pixm->width;
  352. dma->height = pixm->height;
  353. fimc_is_mem_barrier();
  354. isp->video_capture.format = ifmt;
  355. isp->video_capture.pixfmt = *pixm;
  356. return 0;
  357. }
  358. /*
  359. * Check for source/sink format differences at each link.
  360. * Return 0 if the formats match or -EPIPE otherwise.
  361. */
  362. static int isp_video_pipeline_validate(struct fimc_isp *isp)
  363. {
  364. struct v4l2_subdev *sd = &isp->subdev;
  365. struct v4l2_subdev_format sink_fmt, src_fmt;
  366. struct media_pad *pad;
  367. int ret;
  368. while (1) {
  369. /* Retrieve format at the sink pad */
  370. pad = &sd->entity.pads[0];
  371. if (!(pad->flags & MEDIA_PAD_FL_SINK))
  372. break;
  373. sink_fmt.pad = pad->index;
  374. sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
  375. ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sink_fmt);
  376. if (ret < 0 && ret != -ENOIOCTLCMD)
  377. return -EPIPE;
  378. /* Retrieve format at the source pad */
  379. pad = media_entity_remote_pad(pad);
  380. if (pad == NULL ||
  381. media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
  382. break;
  383. sd = media_entity_to_v4l2_subdev(pad->entity);
  384. src_fmt.pad = pad->index;
  385. src_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
  386. ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &src_fmt);
  387. if (ret < 0 && ret != -ENOIOCTLCMD)
  388. return -EPIPE;
  389. if (src_fmt.format.width != sink_fmt.format.width ||
  390. src_fmt.format.height != sink_fmt.format.height ||
  391. src_fmt.format.code != sink_fmt.format.code)
  392. return -EPIPE;
  393. }
  394. return 0;
  395. }
  396. static int isp_video_streamon(struct file *file, void *priv,
  397. enum v4l2_buf_type type)
  398. {
  399. struct fimc_isp *isp = video_drvdata(file);
  400. struct exynos_video_entity *ve = &isp->video_capture.ve;
  401. struct media_entity *me = &ve->vdev.entity;
  402. int ret;
  403. ret = media_entity_pipeline_start(me, &ve->pipe->mp);
  404. if (ret < 0)
  405. return ret;
  406. ret = isp_video_pipeline_validate(isp);
  407. if (ret < 0)
  408. goto p_stop;
  409. ret = vb2_ioctl_streamon(file, priv, type);
  410. if (ret < 0)
  411. goto p_stop;
  412. isp->video_capture.streaming = 1;
  413. return 0;
  414. p_stop:
  415. media_entity_pipeline_stop(me);
  416. return ret;
  417. }
  418. static int isp_video_streamoff(struct file *file, void *priv,
  419. enum v4l2_buf_type type)
  420. {
  421. struct fimc_isp *isp = video_drvdata(file);
  422. struct fimc_is_video *video = &isp->video_capture;
  423. int ret;
  424. ret = vb2_ioctl_streamoff(file, priv, type);
  425. if (ret < 0)
  426. return ret;
  427. media_entity_pipeline_stop(&video->ve.vdev.entity);
  428. video->streaming = 0;
  429. return 0;
  430. }
  431. static int isp_video_reqbufs(struct file *file, void *priv,
  432. struct v4l2_requestbuffers *rb)
  433. {
  434. struct fimc_isp *isp = video_drvdata(file);
  435. int ret;
  436. ret = vb2_ioctl_reqbufs(file, priv, rb);
  437. if (ret < 0)
  438. return ret;
  439. if (rb->count && rb->count < FIMC_ISP_REQ_BUFS_MIN) {
  440. rb->count = 0;
  441. vb2_ioctl_reqbufs(file, priv, rb);
  442. ret = -ENOMEM;
  443. }
  444. isp->video_capture.reqbufs_count = rb->count;
  445. return ret;
  446. }
  447. static const struct v4l2_ioctl_ops isp_video_ioctl_ops = {
  448. .vidioc_querycap = isp_video_querycap,
  449. .vidioc_enum_fmt_vid_cap_mplane = isp_video_enum_fmt_mplane,
  450. .vidioc_try_fmt_vid_cap_mplane = isp_video_try_fmt_mplane,
  451. .vidioc_s_fmt_vid_cap_mplane = isp_video_s_fmt_mplane,
  452. .vidioc_g_fmt_vid_cap_mplane = isp_video_g_fmt_mplane,
  453. .vidioc_reqbufs = isp_video_reqbufs,
  454. .vidioc_querybuf = vb2_ioctl_querybuf,
  455. .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  456. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  457. .vidioc_qbuf = vb2_ioctl_qbuf,
  458. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  459. .vidioc_streamon = isp_video_streamon,
  460. .vidioc_streamoff = isp_video_streamoff,
  461. };
  462. int fimc_isp_video_device_register(struct fimc_isp *isp,
  463. struct v4l2_device *v4l2_dev,
  464. enum v4l2_buf_type type)
  465. {
  466. struct vb2_queue *q = &isp->video_capture.vb_queue;
  467. struct fimc_is_video *iv;
  468. struct video_device *vdev;
  469. int ret;
  470. if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  471. iv = &isp->video_capture;
  472. else
  473. return -ENOSYS;
  474. mutex_init(&isp->video_lock);
  475. INIT_LIST_HEAD(&iv->pending_buf_q);
  476. INIT_LIST_HEAD(&iv->active_buf_q);
  477. iv->format = fimc_isp_find_format(NULL, NULL, 0);
  478. iv->pixfmt.width = IS_DEFAULT_WIDTH;
  479. iv->pixfmt.height = IS_DEFAULT_HEIGHT;
  480. iv->pixfmt.pixelformat = iv->format->fourcc;
  481. iv->pixfmt.colorspace = V4L2_COLORSPACE_SRGB;
  482. iv->reqbufs_count = 0;
  483. memset(q, 0, sizeof(*q));
  484. q->type = type;
  485. q->io_modes = VB2_MMAP | VB2_USERPTR;
  486. q->ops = &isp_video_capture_qops;
  487. q->mem_ops = &vb2_dma_contig_memops;
  488. q->buf_struct_size = sizeof(struct isp_video_buf);
  489. q->drv_priv = isp;
  490. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  491. q->lock = &isp->video_lock;
  492. ret = vb2_queue_init(q);
  493. if (ret < 0)
  494. return ret;
  495. vdev = &iv->ve.vdev;
  496. memset(vdev, 0, sizeof(*vdev));
  497. snprintf(vdev->name, sizeof(vdev->name), "fimc-is-isp.%s",
  498. type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ?
  499. "capture" : "output");
  500. vdev->queue = q;
  501. vdev->fops = &isp_video_fops;
  502. vdev->ioctl_ops = &isp_video_ioctl_ops;
  503. vdev->v4l2_dev = v4l2_dev;
  504. vdev->minor = -1;
  505. vdev->release = video_device_release_empty;
  506. vdev->lock = &isp->video_lock;
  507. iv->pad.flags = MEDIA_PAD_FL_SINK;
  508. ret = media_entity_init(&vdev->entity, 1, &iv->pad, 0);
  509. if (ret < 0)
  510. return ret;
  511. video_set_drvdata(vdev, isp);
  512. ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
  513. if (ret < 0) {
  514. media_entity_cleanup(&vdev->entity);
  515. return ret;
  516. }
  517. v4l2_info(v4l2_dev, "Registered %s as /dev/%s\n",
  518. vdev->name, video_device_node_name(vdev));
  519. return 0;
  520. }
  521. void fimc_isp_video_device_unregister(struct fimc_isp *isp,
  522. enum v4l2_buf_type type)
  523. {
  524. struct exynos_video_entity *ve;
  525. if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  526. ve = &isp->video_capture.ve;
  527. else
  528. return;
  529. mutex_lock(&isp->video_lock);
  530. if (video_is_registered(&ve->vdev)) {
  531. video_unregister_device(&ve->vdev);
  532. media_entity_cleanup(&ve->vdev.entity);
  533. ve->pipe = NULL;
  534. }
  535. mutex_unlock(&isp->video_lock);
  536. }