Linux-libre 4.14.68-gnu
[librecmc/linux-libre.git] / drivers / media / platform / vsp1 / vsp1_histo.h
1 /*
2  * vsp1_histo.h  --  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 #ifndef __VSP1_HISTO_H__
15 #define __VSP1_HISTO_H__
16
17 #include <linux/list.h>
18 #include <linux/mutex.h>
19 #include <linux/spinlock.h>
20
21 #include <media/media-entity.h>
22 #include <media/v4l2-dev.h>
23 #include <media/videobuf2-v4l2.h>
24
25 #include "vsp1_entity.h"
26
27 struct vsp1_device;
28 struct vsp1_pipeline;
29
30 #define HISTO_PAD_SINK                          0
31 #define HISTO_PAD_SOURCE                        1
32
33 struct vsp1_histogram_buffer {
34         struct vb2_v4l2_buffer buf;
35         struct list_head queue;
36         void *addr;
37 };
38
39 struct vsp1_histogram {
40         struct vsp1_pipeline *pipe;
41
42         struct vsp1_entity entity;
43         struct video_device video;
44         struct media_pad pad;
45
46         const u32 *formats;
47         unsigned int num_formats;
48         size_t data_size;
49         u32 meta_format;
50
51         struct mutex lock;
52         struct vb2_queue queue;
53
54         spinlock_t irqlock;
55         struct list_head irqqueue;
56
57         wait_queue_head_t wait_queue;
58         bool readout;
59 };
60
61 static inline struct vsp1_histogram *vdev_to_histo(struct video_device *vdev)
62 {
63         return container_of(vdev, struct vsp1_histogram, video);
64 }
65
66 static inline struct vsp1_histogram *subdev_to_histo(struct v4l2_subdev *subdev)
67 {
68         return container_of(subdev, struct vsp1_histogram, entity.subdev);
69 }
70
71 int vsp1_histogram_init(struct vsp1_device *vsp1, struct vsp1_histogram *histo,
72                         enum vsp1_entity_type type, const char *name,
73                         const struct vsp1_entity_operations *ops,
74                         const unsigned int *formats, unsigned int num_formats,
75                         size_t data_size, u32 meta_format);
76 void vsp1_histogram_destroy(struct vsp1_entity *entity);
77
78 struct vsp1_histogram_buffer *
79 vsp1_histogram_buffer_get(struct vsp1_histogram *histo);
80 void vsp1_histogram_buffer_complete(struct vsp1_histogram *histo,
81                                     struct vsp1_histogram_buffer *buf,
82                                     size_t size);
83
84 #endif /* __VSP1_HISTO_H__ */