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