GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / media / platform / vsp1 / vsp1_entity.h
1 /*
2  * vsp1_entity.h  --  R-Car VSP1 Base Entity
3  *
4  * Copyright (C) 2013-2014 Renesas Electronics Corporation
5  *
6  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13 #ifndef __VSP1_ENTITY_H__
14 #define __VSP1_ENTITY_H__
15
16 #include <linux/list.h>
17 #include <linux/mutex.h>
18
19 #include <media/v4l2-subdev.h>
20
21 struct vsp1_device;
22 struct vsp1_dl_list;
23 struct vsp1_pipeline;
24 struct vsp1_partition;
25 struct vsp1_partition_window;
26
27 enum vsp1_entity_type {
28         VSP1_ENTITY_BRS,
29         VSP1_ENTITY_BRU,
30         VSP1_ENTITY_CLU,
31         VSP1_ENTITY_HGO,
32         VSP1_ENTITY_HGT,
33         VSP1_ENTITY_HSI,
34         VSP1_ENTITY_HST,
35         VSP1_ENTITY_LIF,
36         VSP1_ENTITY_LUT,
37         VSP1_ENTITY_RPF,
38         VSP1_ENTITY_SRU,
39         VSP1_ENTITY_UDS,
40         VSP1_ENTITY_WPF,
41 };
42
43 /**
44  * enum vsp1_entity_params - Entity configuration parameters class
45  * @VSP1_ENTITY_PARAMS_INIT - Initial parameters
46  * @VSP1_ENTITY_PARAMS_PARTITION - Per-image partition parameters
47  * @VSP1_ENTITY_PARAMS_RUNTIME - Runtime-configurable parameters
48  */
49 enum vsp1_entity_params {
50         VSP1_ENTITY_PARAMS_INIT,
51         VSP1_ENTITY_PARAMS_PARTITION,
52         VSP1_ENTITY_PARAMS_RUNTIME,
53 };
54
55 #define VSP1_ENTITY_MAX_INPUTS          5       /* For the BRU */
56
57 /*
58  * struct vsp1_route - Entity routing configuration
59  * @type: Entity type this routing entry is associated with
60  * @index: Entity index this routing entry is associated with
61  * @reg: Output routing configuration register
62  * @inputs: Target node value for each input
63  * @output: Target node value for entity output
64  *
65  * Each $vsp1_route entry describes routing configuration for the entity
66  * specified by the entry's @type and @index. @reg indicates the register that
67  * holds output routing configuration for the entity, and the @inputs array
68  * store the target node value for each input of the entity. The @output field
69  * stores the target node value of the entity output when used as a source for
70  * histogram generation.
71  */
72 struct vsp1_route {
73         enum vsp1_entity_type type;
74         unsigned int index;
75         unsigned int reg;
76         unsigned int inputs[VSP1_ENTITY_MAX_INPUTS];
77         unsigned int output;
78 };
79
80 /**
81  * struct vsp1_entity_operations - Entity operations
82  * @destroy:    Destroy the entity.
83  * @configure:  Setup the hardware based on the entity state (pipeline, formats,
84  *              selection rectangles, ...)
85  * @max_width:  Return the max supported width of data that the entity can
86  *              process in a single operation.
87  * @partition:  Process the partition construction based on this entity's
88  *              configuration.
89  */
90 struct vsp1_entity_operations {
91         void (*destroy)(struct vsp1_entity *);
92         void (*configure)(struct vsp1_entity *, struct vsp1_pipeline *,
93                           struct vsp1_dl_list *, enum vsp1_entity_params);
94         unsigned int (*max_width)(struct vsp1_entity *, struct vsp1_pipeline *);
95         void (*partition)(struct vsp1_entity *, struct vsp1_pipeline *,
96                           struct vsp1_partition *, unsigned int,
97                           struct vsp1_partition_window *);
98 };
99
100 struct vsp1_entity {
101         struct vsp1_device *vsp1;
102
103         const struct vsp1_entity_operations *ops;
104
105         enum vsp1_entity_type type;
106         unsigned int index;
107         const struct vsp1_route *route;
108
109         struct list_head list_dev;
110         struct list_head list_pipe;
111
112         struct media_pad *pads;
113         unsigned int source_pad;
114
115         struct vsp1_entity **sources;
116         struct vsp1_entity *sink;
117         unsigned int sink_pad;
118
119         struct v4l2_subdev subdev;
120         struct v4l2_subdev_pad_config *config;
121
122         struct mutex lock;      /* Protects the pad config */
123 };
124
125 static inline struct vsp1_entity *to_vsp1_entity(struct v4l2_subdev *subdev)
126 {
127         return container_of(subdev, struct vsp1_entity, subdev);
128 }
129
130 int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
131                      const char *name, unsigned int num_pads,
132                      const struct v4l2_subdev_ops *ops, u32 function);
133 void vsp1_entity_destroy(struct vsp1_entity *entity);
134
135 extern const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops;
136
137 int vsp1_entity_link_setup(struct media_entity *entity,
138                            const struct media_pad *local,
139                            const struct media_pad *remote, u32 flags);
140
141 struct v4l2_subdev_pad_config *
142 vsp1_entity_get_pad_config(struct vsp1_entity *entity,
143                            struct v4l2_subdev_pad_config *cfg,
144                            enum v4l2_subdev_format_whence which);
145 struct v4l2_mbus_framefmt *
146 vsp1_entity_get_pad_format(struct vsp1_entity *entity,
147                            struct v4l2_subdev_pad_config *cfg,
148                            unsigned int pad);
149 struct v4l2_rect *
150 vsp1_entity_get_pad_selection(struct vsp1_entity *entity,
151                               struct v4l2_subdev_pad_config *cfg,
152                               unsigned int pad, unsigned int target);
153 int vsp1_entity_init_cfg(struct v4l2_subdev *subdev,
154                          struct v4l2_subdev_pad_config *cfg);
155
156 void vsp1_entity_route_setup(struct vsp1_entity *entity,
157                              struct vsp1_pipeline *pipe,
158                              struct vsp1_dl_list *dl);
159
160 struct media_pad *vsp1_entity_remote_pad(struct media_pad *pad);
161
162 int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
163                                struct v4l2_subdev_pad_config *cfg,
164                                struct v4l2_subdev_format *fmt);
165 int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
166                                struct v4l2_subdev_pad_config *cfg,
167                                struct v4l2_subdev_mbus_code_enum *code,
168                                const unsigned int *codes, unsigned int ncodes);
169 int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev,
170                                 struct v4l2_subdev_pad_config *cfg,
171                                 struct v4l2_subdev_frame_size_enum *fse,
172                                 unsigned int min_w, unsigned int min_h,
173                                 unsigned int max_w, unsigned int max_h);
174
175 #endif /* __VSP1_ENTITY_H__ */