1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * vsp1_histo.h  --  R-Car VSP1 Histogram API
4  *
5  * Copyright (C) 2016 Renesas Electronics Corporation
6  * Copyright (C) 2016 Laurent Pinchart
7  *
8  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
9  */
10 #ifndef __VSP1_HISTO_H__
11 #define __VSP1_HISTO_H__
12 
13 #include <linux/list.h>
14 #include <linux/mutex.h>
15 #include <linux/spinlock.h>
16 
17 #include <media/media-entity.h>
18 #include <media/v4l2-dev.h>
19 #include <media/videobuf2-v4l2.h>
20 
21 #include "vsp1_entity.h"
22 
23 struct vsp1_device;
24 
25 #define HISTO_PAD_SINK				0
26 #define HISTO_PAD_SOURCE			1
27 
28 struct vsp1_histogram_buffer {
29 	struct vb2_v4l2_buffer buf;
30 	struct list_head queue;
31 	void *addr;
32 };
33 
34 struct vsp1_histogram {
35 	struct vsp1_entity entity;
36 	struct video_device video;
37 	struct media_pad pad;
38 
39 	const u32 *formats;
40 	unsigned int num_formats;
41 	size_t data_size;
42 	u32 meta_format;
43 
44 	struct mutex lock;
45 	struct vb2_queue queue;
46 
47 	spinlock_t irqlock;
48 	struct list_head irqqueue;
49 
50 	wait_queue_head_t wait_queue;
51 	bool readout;
52 };
53 
vdev_to_histo(struct video_device * vdev)54 static inline struct vsp1_histogram *vdev_to_histo(struct video_device *vdev)
55 {
56 	return container_of(vdev, struct vsp1_histogram, video);
57 }
58 
subdev_to_histo(struct v4l2_subdev * subdev)59 static inline struct vsp1_histogram *subdev_to_histo(struct v4l2_subdev *subdev)
60 {
61 	return container_of(subdev, struct vsp1_histogram, entity.subdev);
62 }
63 
64 int vsp1_histogram_init(struct vsp1_device *vsp1, struct vsp1_histogram *histo,
65 			enum vsp1_entity_type type, const char *name,
66 			const struct vsp1_entity_operations *ops,
67 			const unsigned int *formats, unsigned int num_formats,
68 			size_t data_size, u32 meta_format);
69 void vsp1_histogram_destroy(struct vsp1_entity *entity);
70 
71 struct vsp1_histogram_buffer *
72 vsp1_histogram_buffer_get(struct vsp1_histogram *histo);
73 void vsp1_histogram_buffer_complete(struct vsp1_histogram *histo,
74 				    struct vsp1_histogram_buffer *buf,
75 				    size_t size);
76 
77 #endif /* __VSP1_HISTO_H__ */
78