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