vsp1_histo.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * vsp1_histo.c -- R-Car VSP1 Histogram API
  3. *
  4. * Copyright (C) 2016 Renesas Electronics Corporation
  5. * Copyright (C) 2016 Laurent Pinchart
  6. *
  7. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include <linux/device.h>
  15. #include <linux/gfp.h>
  16. #include <media/v4l2-ioctl.h>
  17. #include <media/v4l2-subdev.h>
  18. #include <media/videobuf2-vmalloc.h>
  19. #include "vsp1.h"
  20. #include "vsp1_histo.h"
  21. #include "vsp1_pipe.h"
  22. #define HISTO_MIN_SIZE 4U
  23. #define HISTO_MAX_SIZE 8192U
  24. /* -----------------------------------------------------------------------------
  25. * Buffer Operations
  26. */
  27. static inline struct vsp1_histogram_buffer *
  28. to_vsp1_histogram_buffer(struct vb2_v4l2_buffer *vbuf)
  29. {
  30. return container_of(vbuf, struct vsp1_histogram_buffer, buf);
  31. }
  32. struct vsp1_histogram_buffer *
  33. vsp1_histogram_buffer_get(struct vsp1_histogram *histo)
  34. {
  35. struct vsp1_histogram_buffer *buf = NULL;
  36. unsigned long flags;
  37. spin_lock_irqsave(&histo->irqlock, flags);
  38. if (list_empty(&histo->irqqueue))
  39. goto done;
  40. buf = list_first_entry(&histo->irqqueue, struct vsp1_histogram_buffer,
  41. queue);
  42. list_del(&buf->queue);
  43. histo->readout = true;
  44. done:
  45. spin_unlock_irqrestore(&histo->irqlock, flags);
  46. return buf;
  47. }
  48. void vsp1_histogram_buffer_complete(struct vsp1_histogram *histo,
  49. struct vsp1_histogram_buffer *buf,
  50. size_t size)
  51. {
  52. struct vsp1_pipeline *pipe = histo->pipe;
  53. unsigned long flags;
  54. /*
  55. * The pipeline pointer is guaranteed to be valid as this function is
  56. * called from the frame completion interrupt handler, which can only
  57. * occur when video streaming is active.
  58. */
  59. buf->buf.sequence = pipe->sequence;
  60. buf->buf.vb2_buf.timestamp = ktime_get_ns();
  61. vb2_set_plane_payload(&buf->buf.vb2_buf, 0, size);
  62. vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
  63. spin_lock_irqsave(&histo->irqlock, flags);
  64. histo->readout = false;
  65. wake_up(&histo->wait_queue);
  66. spin_unlock_irqrestore(&histo->irqlock, flags);
  67. }
  68. /* -----------------------------------------------------------------------------
  69. * videobuf2 Queue Operations
  70. */
  71. static int histo_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
  72. unsigned int *nplanes, unsigned int sizes[],
  73. struct device *alloc_devs[])
  74. {
  75. struct vsp1_histogram *histo = vb2_get_drv_priv(vq);
  76. if (*nplanes) {
  77. if (*nplanes != 1)
  78. return -EINVAL;
  79. if (sizes[0] < histo->data_size)
  80. return -EINVAL;
  81. return 0;
  82. }
  83. *nplanes = 1;
  84. sizes[0] = histo->data_size;
  85. return 0;
  86. }
  87. static int histo_buffer_prepare(struct vb2_buffer *vb)
  88. {
  89. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  90. struct vsp1_histogram *histo = vb2_get_drv_priv(vb->vb2_queue);
  91. struct vsp1_histogram_buffer *buf = to_vsp1_histogram_buffer(vbuf);
  92. if (vb->num_planes != 1)
  93. return -EINVAL;
  94. if (vb2_plane_size(vb, 0) < histo->data_size)
  95. return -EINVAL;
  96. buf->addr = vb2_plane_vaddr(vb, 0);
  97. return 0;
  98. }
  99. static void histo_buffer_queue(struct vb2_buffer *vb)
  100. {
  101. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  102. struct vsp1_histogram *histo = vb2_get_drv_priv(vb->vb2_queue);
  103. struct vsp1_histogram_buffer *buf = to_vsp1_histogram_buffer(vbuf);
  104. unsigned long flags;
  105. spin_lock_irqsave(&histo->irqlock, flags);
  106. list_add_tail(&buf->queue, &histo->irqqueue);
  107. spin_unlock_irqrestore(&histo->irqlock, flags);
  108. }
  109. static int histo_start_streaming(struct vb2_queue *vq, unsigned int count)
  110. {
  111. return 0;
  112. }
  113. static void histo_stop_streaming(struct vb2_queue *vq)
  114. {
  115. struct vsp1_histogram *histo = vb2_get_drv_priv(vq);
  116. struct vsp1_histogram_buffer *buffer;
  117. unsigned long flags;
  118. spin_lock_irqsave(&histo->irqlock, flags);
  119. /* Remove all buffers from the IRQ queue. */
  120. list_for_each_entry(buffer, &histo->irqqueue, queue)
  121. vb2_buffer_done(&buffer->buf.vb2_buf, VB2_BUF_STATE_ERROR);
  122. INIT_LIST_HEAD(&histo->irqqueue);
  123. /* Wait for the buffer being read out (if any) to complete. */
  124. wait_event_lock_irq(histo->wait_queue, !histo->readout, histo->irqlock);
  125. spin_unlock_irqrestore(&histo->irqlock, flags);
  126. }
  127. static const struct vb2_ops histo_video_queue_qops = {
  128. .queue_setup = histo_queue_setup,
  129. .buf_prepare = histo_buffer_prepare,
  130. .buf_queue = histo_buffer_queue,
  131. .wait_prepare = vb2_ops_wait_prepare,
  132. .wait_finish = vb2_ops_wait_finish,
  133. .start_streaming = histo_start_streaming,
  134. .stop_streaming = histo_stop_streaming,
  135. };
  136. /* -----------------------------------------------------------------------------
  137. * V4L2 Subdevice Operations
  138. */
  139. static int histo_enum_mbus_code(struct v4l2_subdev *subdev,
  140. struct v4l2_subdev_pad_config *cfg,
  141. struct v4l2_subdev_mbus_code_enum *code)
  142. {
  143. struct vsp1_histogram *histo = subdev_to_histo(subdev);
  144. if (code->pad == HISTO_PAD_SOURCE) {
  145. code->code = MEDIA_BUS_FMT_FIXED;
  146. return 0;
  147. }
  148. return vsp1_subdev_enum_mbus_code(subdev, cfg, code, histo->formats,
  149. histo->num_formats);
  150. }
  151. static int histo_enum_frame_size(struct v4l2_subdev *subdev,
  152. struct v4l2_subdev_pad_config *cfg,
  153. struct v4l2_subdev_frame_size_enum *fse)
  154. {
  155. if (fse->pad != HISTO_PAD_SINK)
  156. return -EINVAL;
  157. return vsp1_subdev_enum_frame_size(subdev, cfg, fse, HISTO_MIN_SIZE,
  158. HISTO_MIN_SIZE, HISTO_MAX_SIZE,
  159. HISTO_MAX_SIZE);
  160. }
  161. static int histo_get_selection(struct v4l2_subdev *subdev,
  162. struct v4l2_subdev_pad_config *cfg,
  163. struct v4l2_subdev_selection *sel)
  164. {
  165. struct vsp1_histogram *histo = subdev_to_histo(subdev);
  166. struct v4l2_subdev_pad_config *config;
  167. struct v4l2_mbus_framefmt *format;
  168. struct v4l2_rect *crop;
  169. int ret = 0;
  170. if (sel->pad != HISTO_PAD_SINK)
  171. return -EINVAL;
  172. mutex_lock(&histo->entity.lock);
  173. config = vsp1_entity_get_pad_config(&histo->entity, cfg, sel->which);
  174. if (!config) {
  175. ret = -EINVAL;
  176. goto done;
  177. }
  178. switch (sel->target) {
  179. case V4L2_SEL_TGT_COMPOSE_BOUNDS:
  180. case V4L2_SEL_TGT_COMPOSE_DEFAULT:
  181. crop = vsp1_entity_get_pad_selection(&histo->entity, config,
  182. HISTO_PAD_SINK,
  183. V4L2_SEL_TGT_CROP);
  184. sel->r.left = 0;
  185. sel->r.top = 0;
  186. sel->r.width = crop->width;
  187. sel->r.height = crop->height;
  188. break;
  189. case V4L2_SEL_TGT_CROP_BOUNDS:
  190. case V4L2_SEL_TGT_CROP_DEFAULT:
  191. format = vsp1_entity_get_pad_format(&histo->entity, config,
  192. HISTO_PAD_SINK);
  193. sel->r.left = 0;
  194. sel->r.top = 0;
  195. sel->r.width = format->width;
  196. sel->r.height = format->height;
  197. break;
  198. case V4L2_SEL_TGT_COMPOSE:
  199. case V4L2_SEL_TGT_CROP:
  200. sel->r = *vsp1_entity_get_pad_selection(&histo->entity, config,
  201. sel->pad, sel->target);
  202. break;
  203. default:
  204. ret = -EINVAL;
  205. break;
  206. }
  207. done:
  208. mutex_unlock(&histo->entity.lock);
  209. return ret;
  210. }
  211. static int histo_set_crop(struct v4l2_subdev *subdev,
  212. struct v4l2_subdev_pad_config *config,
  213. struct v4l2_subdev_selection *sel)
  214. {
  215. struct vsp1_histogram *histo = subdev_to_histo(subdev);
  216. struct v4l2_mbus_framefmt *format;
  217. struct v4l2_rect *selection;
  218. /* The crop rectangle must be inside the input frame. */
  219. format = vsp1_entity_get_pad_format(&histo->entity, config,
  220. HISTO_PAD_SINK);
  221. sel->r.left = clamp_t(unsigned int, sel->r.left, 0, format->width - 1);
  222. sel->r.top = clamp_t(unsigned int, sel->r.top, 0, format->height - 1);
  223. sel->r.width = clamp_t(unsigned int, sel->r.width, HISTO_MIN_SIZE,
  224. format->width - sel->r.left);
  225. sel->r.height = clamp_t(unsigned int, sel->r.height, HISTO_MIN_SIZE,
  226. format->height - sel->r.top);
  227. /* Set the crop rectangle and reset the compose rectangle. */
  228. selection = vsp1_entity_get_pad_selection(&histo->entity, config,
  229. sel->pad, V4L2_SEL_TGT_CROP);
  230. *selection = sel->r;
  231. selection = vsp1_entity_get_pad_selection(&histo->entity, config,
  232. sel->pad,
  233. V4L2_SEL_TGT_COMPOSE);
  234. *selection = sel->r;
  235. return 0;
  236. }
  237. static int histo_set_compose(struct v4l2_subdev *subdev,
  238. struct v4l2_subdev_pad_config *config,
  239. struct v4l2_subdev_selection *sel)
  240. {
  241. struct vsp1_histogram *histo = subdev_to_histo(subdev);
  242. struct v4l2_rect *compose;
  243. struct v4l2_rect *crop;
  244. unsigned int ratio;
  245. /*
  246. * The compose rectangle is used to configure downscaling, the top left
  247. * corner is fixed to (0,0) and the size to 1/2 or 1/4 of the crop
  248. * rectangle.
  249. */
  250. sel->r.left = 0;
  251. sel->r.top = 0;
  252. crop = vsp1_entity_get_pad_selection(&histo->entity, config, sel->pad,
  253. V4L2_SEL_TGT_CROP);
  254. /*
  255. * Clamp the width and height to acceptable values first and then
  256. * compute the closest rounded dividing ratio.
  257. *
  258. * Ratio Rounded ratio
  259. * --------------------------
  260. * [1.0 1.5[ 1
  261. * [1.5 3.0[ 2
  262. * [3.0 4.0] 4
  263. *
  264. * The rounded ratio can be computed using
  265. *
  266. * 1 << (ceil(ratio * 2) / 3)
  267. */
  268. sel->r.width = clamp(sel->r.width, crop->width / 4, crop->width);
  269. ratio = 1 << (crop->width * 2 / sel->r.width / 3);
  270. sel->r.width = crop->width / ratio;
  271. sel->r.height = clamp(sel->r.height, crop->height / 4, crop->height);
  272. ratio = 1 << (crop->height * 2 / sel->r.height / 3);
  273. sel->r.height = crop->height / ratio;
  274. compose = vsp1_entity_get_pad_selection(&histo->entity, config,
  275. sel->pad,
  276. V4L2_SEL_TGT_COMPOSE);
  277. *compose = sel->r;
  278. return 0;
  279. }
  280. static int histo_set_selection(struct v4l2_subdev *subdev,
  281. struct v4l2_subdev_pad_config *cfg,
  282. struct v4l2_subdev_selection *sel)
  283. {
  284. struct vsp1_histogram *histo = subdev_to_histo(subdev);
  285. struct v4l2_subdev_pad_config *config;
  286. int ret;
  287. if (sel->pad != HISTO_PAD_SINK)
  288. return -EINVAL;
  289. mutex_lock(&histo->entity.lock);
  290. config = vsp1_entity_get_pad_config(&histo->entity, cfg, sel->which);
  291. if (!config) {
  292. ret = -EINVAL;
  293. goto done;
  294. }
  295. if (sel->target == V4L2_SEL_TGT_CROP)
  296. ret = histo_set_crop(subdev, config, sel);
  297. else if (sel->target == V4L2_SEL_TGT_COMPOSE)
  298. ret = histo_set_compose(subdev, config, sel);
  299. else
  300. ret = -EINVAL;
  301. done:
  302. mutex_unlock(&histo->entity.lock);
  303. return ret;
  304. }
  305. static int histo_get_format(struct v4l2_subdev *subdev,
  306. struct v4l2_subdev_pad_config *cfg,
  307. struct v4l2_subdev_format *fmt)
  308. {
  309. if (fmt->pad == HISTO_PAD_SOURCE) {
  310. fmt->format.code = MEDIA_BUS_FMT_FIXED;
  311. fmt->format.width = 0;
  312. fmt->format.height = 0;
  313. fmt->format.field = V4L2_FIELD_NONE;
  314. fmt->format.colorspace = V4L2_COLORSPACE_RAW;
  315. return 0;
  316. }
  317. return vsp1_subdev_get_pad_format(subdev, cfg, fmt);
  318. }
  319. static int histo_set_format(struct v4l2_subdev *subdev,
  320. struct v4l2_subdev_pad_config *cfg,
  321. struct v4l2_subdev_format *fmt)
  322. {
  323. struct vsp1_histogram *histo = subdev_to_histo(subdev);
  324. struct v4l2_subdev_pad_config *config;
  325. struct v4l2_mbus_framefmt *format;
  326. struct v4l2_rect *selection;
  327. unsigned int i;
  328. int ret = 0;
  329. if (fmt->pad != HISTO_PAD_SINK)
  330. return histo_get_format(subdev, cfg, fmt);
  331. mutex_lock(&histo->entity.lock);
  332. config = vsp1_entity_get_pad_config(&histo->entity, cfg, fmt->which);
  333. if (!config) {
  334. ret = -EINVAL;
  335. goto done;
  336. }
  337. /*
  338. * Default to the first format if the requested format is not
  339. * supported.
  340. */
  341. for (i = 0; i < histo->num_formats; ++i) {
  342. if (fmt->format.code == histo->formats[i])
  343. break;
  344. }
  345. if (i == histo->num_formats)
  346. fmt->format.code = histo->formats[0];
  347. format = vsp1_entity_get_pad_format(&histo->entity, config, fmt->pad);
  348. format->code = fmt->format.code;
  349. format->width = clamp_t(unsigned int, fmt->format.width,
  350. HISTO_MIN_SIZE, HISTO_MAX_SIZE);
  351. format->height = clamp_t(unsigned int, fmt->format.height,
  352. HISTO_MIN_SIZE, HISTO_MAX_SIZE);
  353. format->field = V4L2_FIELD_NONE;
  354. format->colorspace = V4L2_COLORSPACE_SRGB;
  355. fmt->format = *format;
  356. /* Reset the crop and compose rectangles */
  357. selection = vsp1_entity_get_pad_selection(&histo->entity, config,
  358. fmt->pad, V4L2_SEL_TGT_CROP);
  359. selection->left = 0;
  360. selection->top = 0;
  361. selection->width = format->width;
  362. selection->height = format->height;
  363. selection = vsp1_entity_get_pad_selection(&histo->entity, config,
  364. fmt->pad,
  365. V4L2_SEL_TGT_COMPOSE);
  366. selection->left = 0;
  367. selection->top = 0;
  368. selection->width = format->width;
  369. selection->height = format->height;
  370. done:
  371. mutex_unlock(&histo->entity.lock);
  372. return ret;
  373. }
  374. static const struct v4l2_subdev_pad_ops histo_pad_ops = {
  375. .enum_mbus_code = histo_enum_mbus_code,
  376. .enum_frame_size = histo_enum_frame_size,
  377. .get_fmt = histo_get_format,
  378. .set_fmt = histo_set_format,
  379. .get_selection = histo_get_selection,
  380. .set_selection = histo_set_selection,
  381. };
  382. static const struct v4l2_subdev_ops histo_ops = {
  383. .pad = &histo_pad_ops,
  384. };
  385. /* -----------------------------------------------------------------------------
  386. * V4L2 ioctls
  387. */
  388. static int histo_v4l2_querycap(struct file *file, void *fh,
  389. struct v4l2_capability *cap)
  390. {
  391. struct v4l2_fh *vfh = file->private_data;
  392. struct vsp1_histogram *histo = vdev_to_histo(vfh->vdev);
  393. cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
  394. | V4L2_CAP_VIDEO_CAPTURE_MPLANE
  395. | V4L2_CAP_VIDEO_OUTPUT_MPLANE
  396. | V4L2_CAP_META_CAPTURE;
  397. cap->device_caps = V4L2_CAP_META_CAPTURE
  398. | V4L2_CAP_STREAMING;
  399. strlcpy(cap->driver, "vsp1", sizeof(cap->driver));
  400. strlcpy(cap->card, histo->video.name, sizeof(cap->card));
  401. snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
  402. dev_name(histo->entity.vsp1->dev));
  403. return 0;
  404. }
  405. static int histo_v4l2_enum_format(struct file *file, void *fh,
  406. struct v4l2_fmtdesc *f)
  407. {
  408. struct v4l2_fh *vfh = file->private_data;
  409. struct vsp1_histogram *histo = vdev_to_histo(vfh->vdev);
  410. if (f->index > 0 || f->type != histo->queue.type)
  411. return -EINVAL;
  412. f->pixelformat = histo->meta_format;
  413. return 0;
  414. }
  415. static int histo_v4l2_get_format(struct file *file, void *fh,
  416. struct v4l2_format *format)
  417. {
  418. struct v4l2_fh *vfh = file->private_data;
  419. struct vsp1_histogram *histo = vdev_to_histo(vfh->vdev);
  420. struct v4l2_meta_format *meta = &format->fmt.meta;
  421. if (format->type != histo->queue.type)
  422. return -EINVAL;
  423. memset(meta, 0, sizeof(*meta));
  424. meta->dataformat = histo->meta_format;
  425. meta->buffersize = histo->data_size;
  426. return 0;
  427. }
  428. static const struct v4l2_ioctl_ops histo_v4l2_ioctl_ops = {
  429. .vidioc_querycap = histo_v4l2_querycap,
  430. .vidioc_enum_fmt_meta_cap = histo_v4l2_enum_format,
  431. .vidioc_g_fmt_meta_cap = histo_v4l2_get_format,
  432. .vidioc_s_fmt_meta_cap = histo_v4l2_get_format,
  433. .vidioc_try_fmt_meta_cap = histo_v4l2_get_format,
  434. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  435. .vidioc_querybuf = vb2_ioctl_querybuf,
  436. .vidioc_qbuf = vb2_ioctl_qbuf,
  437. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  438. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  439. .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  440. .vidioc_streamon = vb2_ioctl_streamon,
  441. .vidioc_streamoff = vb2_ioctl_streamoff,
  442. };
  443. /* -----------------------------------------------------------------------------
  444. * V4L2 File Operations
  445. */
  446. static const struct v4l2_file_operations histo_v4l2_fops = {
  447. .owner = THIS_MODULE,
  448. .unlocked_ioctl = video_ioctl2,
  449. .open = v4l2_fh_open,
  450. .release = vb2_fop_release,
  451. .poll = vb2_fop_poll,
  452. .mmap = vb2_fop_mmap,
  453. };
  454. static void vsp1_histogram_cleanup(struct vsp1_histogram *histo)
  455. {
  456. if (video_is_registered(&histo->video))
  457. video_unregister_device(&histo->video);
  458. media_entity_cleanup(&histo->video.entity);
  459. }
  460. void vsp1_histogram_destroy(struct vsp1_entity *entity)
  461. {
  462. struct vsp1_histogram *histo = subdev_to_histo(&entity->subdev);
  463. vsp1_histogram_cleanup(histo);
  464. }
  465. int vsp1_histogram_init(struct vsp1_device *vsp1, struct vsp1_histogram *histo,
  466. enum vsp1_entity_type type, const char *name,
  467. const struct vsp1_entity_operations *ops,
  468. const unsigned int *formats, unsigned int num_formats,
  469. size_t data_size, u32 meta_format)
  470. {
  471. int ret;
  472. histo->formats = formats;
  473. histo->num_formats = num_formats;
  474. histo->data_size = data_size;
  475. histo->meta_format = meta_format;
  476. histo->pad.flags = MEDIA_PAD_FL_SINK;
  477. histo->video.vfl_dir = VFL_DIR_RX;
  478. mutex_init(&histo->lock);
  479. spin_lock_init(&histo->irqlock);
  480. INIT_LIST_HEAD(&histo->irqqueue);
  481. init_waitqueue_head(&histo->wait_queue);
  482. /* Initialize the VSP entity... */
  483. histo->entity.ops = ops;
  484. histo->entity.type = type;
  485. ret = vsp1_entity_init(vsp1, &histo->entity, name, 2, &histo_ops,
  486. MEDIA_ENT_F_PROC_VIDEO_STATISTICS);
  487. if (ret < 0)
  488. return ret;
  489. /* ... and the media entity... */
  490. ret = media_entity_pads_init(&histo->video.entity, 1, &histo->pad);
  491. if (ret < 0)
  492. return ret;
  493. /* ... and the video node... */
  494. histo->video.v4l2_dev = &vsp1->v4l2_dev;
  495. histo->video.fops = &histo_v4l2_fops;
  496. snprintf(histo->video.name, sizeof(histo->video.name),
  497. "%s histo", histo->entity.subdev.name);
  498. histo->video.vfl_type = VFL_TYPE_GRABBER;
  499. histo->video.release = video_device_release_empty;
  500. histo->video.ioctl_ops = &histo_v4l2_ioctl_ops;
  501. video_set_drvdata(&histo->video, histo);
  502. /* ... and the buffers queue... */
  503. histo->queue.type = V4L2_BUF_TYPE_META_CAPTURE;
  504. histo->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
  505. histo->queue.lock = &histo->lock;
  506. histo->queue.drv_priv = histo;
  507. histo->queue.buf_struct_size = sizeof(struct vsp1_histogram_buffer);
  508. histo->queue.ops = &histo_video_queue_qops;
  509. histo->queue.mem_ops = &vb2_vmalloc_memops;
  510. histo->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
  511. histo->queue.dev = vsp1->dev;
  512. ret = vb2_queue_init(&histo->queue);
  513. if (ret < 0) {
  514. dev_err(vsp1->dev, "failed to initialize vb2 queue\n");
  515. goto error;
  516. }
  517. /* ... and register the video device. */
  518. histo->video.queue = &histo->queue;
  519. ret = video_register_device(&histo->video, VFL_TYPE_GRABBER, -1);
  520. if (ret < 0) {
  521. dev_err(vsp1->dev, "failed to register video device\n");
  522. goto error;
  523. }
  524. return 0;
  525. error:
  526. vsp1_histogram_cleanup(histo);
  527. return ret;
  528. }