fimc-isp-video.c 17 KB

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