fimc-isp-video.c 17 KB

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