2 * vsp1_entity.c -- R-Car VSP1 Base Entity
4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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.
14 #include <linux/device.h>
15 #include <linux/gfp.h>
17 #include <media/media-entity.h>
18 #include <media/v4l2-ctrls.h>
19 #include <media/v4l2-subdev.h>
23 #include "vsp1_entity.h"
25 void vsp1_entity_route_setup(struct vsp1_entity
*source
,
26 struct vsp1_dl_list
*dl
)
28 struct vsp1_entity
*sink
;
30 if (source
->route
->reg
== 0)
33 sink
= container_of(source
->sink
, struct vsp1_entity
, subdev
.entity
);
34 vsp1_dl_list_write(dl
, source
->route
->reg
,
35 sink
->route
->inputs
[source
->sink_pad
]);
38 /* -----------------------------------------------------------------------------
39 * V4L2 Subdevice Operations
43 * vsp1_entity_get_pad_config - Get the pad configuration for an entity
45 * @cfg: the TRY pad configuration
46 * @which: configuration selector (ACTIVE or TRY)
48 * Return the pad configuration requested by the which argument. The TRY
49 * configuration is passed explicitly to the function through the cfg argument
50 * and simply returned when requested. The ACTIVE configuration comes from the
53 struct v4l2_subdev_pad_config
*
54 vsp1_entity_get_pad_config(struct vsp1_entity
*entity
,
55 struct v4l2_subdev_pad_config
*cfg
,
56 enum v4l2_subdev_format_whence which
)
59 case V4L2_SUBDEV_FORMAT_ACTIVE
:
60 return entity
->config
;
61 case V4L2_SUBDEV_FORMAT_TRY
:
68 * vsp1_entity_get_pad_format - Get a pad format from storage for an entity
70 * @cfg: the configuration storage
71 * @pad: the pad number
73 * Return the format stored in the given configuration for an entity's pad. The
74 * configuration can be an ACTIVE or TRY configuration.
76 struct v4l2_mbus_framefmt
*
77 vsp1_entity_get_pad_format(struct vsp1_entity
*entity
,
78 struct v4l2_subdev_pad_config
*cfg
,
81 return v4l2_subdev_get_try_format(&entity
->subdev
, cfg
, pad
);
85 vsp1_entity_get_pad_compose(struct vsp1_entity
*entity
,
86 struct v4l2_subdev_pad_config
*cfg
,
89 return v4l2_subdev_get_try_compose(&entity
->subdev
, cfg
, pad
);
93 * vsp1_entity_init_cfg - Initialize formats on all pads
94 * @subdev: V4L2 subdevice
95 * @cfg: V4L2 subdev pad configuration
97 * Initialize all pad formats with default values in the given pad config. This
98 * function can be used as a handler for the subdev pad::init_cfg operation.
100 int vsp1_entity_init_cfg(struct v4l2_subdev
*subdev
,
101 struct v4l2_subdev_pad_config
*cfg
)
103 struct v4l2_subdev_format format
;
106 for (pad
= 0; pad
< subdev
->entity
.num_pads
- 1; ++pad
) {
107 memset(&format
, 0, sizeof(format
));
110 format
.which
= cfg
? V4L2_SUBDEV_FORMAT_TRY
111 : V4L2_SUBDEV_FORMAT_ACTIVE
;
113 v4l2_subdev_call(subdev
, pad
, set_fmt
, cfg
, &format
);
120 * vsp1_subdev_get_pad_format - Subdev pad get_fmt handler
121 * @subdev: V4L2 subdevice
122 * @cfg: V4L2 subdev pad configuration
123 * @fmt: V4L2 subdev format
125 * This function implements the subdev get_fmt pad operation. It can be used as
126 * a direct drop-in for the operation handler.
128 int vsp1_subdev_get_pad_format(struct v4l2_subdev
*subdev
,
129 struct v4l2_subdev_pad_config
*cfg
,
130 struct v4l2_subdev_format
*fmt
)
132 struct vsp1_entity
*entity
= to_vsp1_entity(subdev
);
133 struct v4l2_subdev_pad_config
*config
;
135 config
= vsp1_entity_get_pad_config(entity
, cfg
, fmt
->which
);
139 fmt
->format
= *vsp1_entity_get_pad_format(entity
, config
, fmt
->pad
);
145 * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler
146 * @subdev: V4L2 subdevice
147 * @cfg: V4L2 subdev pad configuration
148 * @code: Media bus code enumeration
149 * @codes: Array of supported media bus codes
150 * @ncodes: Number of supported media bus codes
152 * This function implements the subdev enum_mbus_code pad operation for entities
153 * that do not support format conversion. It enumerates the given supported
154 * media bus codes on the sink pad and reports a source pad format identical to
157 int vsp1_subdev_enum_mbus_code(struct v4l2_subdev
*subdev
,
158 struct v4l2_subdev_pad_config
*cfg
,
159 struct v4l2_subdev_mbus_code_enum
*code
,
160 const unsigned int *codes
, unsigned int ncodes
)
162 struct vsp1_entity
*entity
= to_vsp1_entity(subdev
);
164 if (code
->pad
== 0) {
165 if (code
->index
>= ncodes
)
168 code
->code
= codes
[code
->index
];
170 struct v4l2_subdev_pad_config
*config
;
171 struct v4l2_mbus_framefmt
*format
;
173 /* The entity can't perform format conversion, the sink format
174 * is always identical to the source format.
179 config
= vsp1_entity_get_pad_config(entity
, cfg
, code
->which
);
183 format
= vsp1_entity_get_pad_format(entity
, config
, 0);
184 code
->code
= format
->code
;
191 * vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler
192 * @subdev: V4L2 subdevice
193 * @cfg: V4L2 subdev pad configuration
194 * @fse: Frame size enumeration
195 * @min_width: Minimum image width
196 * @min_height: Minimum image height
197 * @max_width: Maximum image width
198 * @max_height: Maximum image height
200 * This function implements the subdev enum_frame_size pad operation for
201 * entities that do not support scaling or cropping. It reports the given
202 * minimum and maximum frame width and height on the sink pad, and a fixed
203 * source pad size identical to the sink pad.
205 int vsp1_subdev_enum_frame_size(struct v4l2_subdev
*subdev
,
206 struct v4l2_subdev_pad_config
*cfg
,
207 struct v4l2_subdev_frame_size_enum
*fse
,
208 unsigned int min_width
, unsigned int min_height
,
209 unsigned int max_width
, unsigned int max_height
)
211 struct vsp1_entity
*entity
= to_vsp1_entity(subdev
);
212 struct v4l2_subdev_pad_config
*config
;
213 struct v4l2_mbus_framefmt
*format
;
215 config
= vsp1_entity_get_pad_config(entity
, cfg
, fse
->which
);
219 format
= vsp1_entity_get_pad_format(entity
, config
, fse
->pad
);
221 if (fse
->index
|| fse
->code
!= format
->code
)
225 fse
->min_width
= min_width
;
226 fse
->max_width
= max_width
;
227 fse
->min_height
= min_height
;
228 fse
->max_height
= max_height
;
230 /* The size on the source pad are fixed and always identical to
231 * the size on the sink pad.
233 fse
->min_width
= format
->width
;
234 fse
->max_width
= format
->width
;
235 fse
->min_height
= format
->height
;
236 fse
->max_height
= format
->height
;
242 /* -----------------------------------------------------------------------------
246 int vsp1_entity_link_setup(struct media_entity
*entity
,
247 const struct media_pad
*local
,
248 const struct media_pad
*remote
, u32 flags
)
250 struct vsp1_entity
*source
;
252 if (!(local
->flags
& MEDIA_PAD_FL_SOURCE
))
255 source
= container_of(local
->entity
, struct vsp1_entity
, subdev
.entity
);
260 if (flags
& MEDIA_LNK_FL_ENABLED
) {
263 source
->sink
= remote
->entity
;
264 source
->sink_pad
= remote
->index
;
267 source
->sink_pad
= 0;
273 /* -----------------------------------------------------------------------------
277 #define VSP1_ENTITY_ROUTE(ent) \
278 { VSP1_ENTITY_##ent, 0, VI6_DPR_##ent##_ROUTE, \
279 { VI6_DPR_NODE_##ent }, VI6_DPR_NODE_##ent }
281 #define VSP1_ENTITY_ROUTE_RPF(idx) \
282 { VSP1_ENTITY_RPF, idx, VI6_DPR_RPF_ROUTE(idx), \
283 { 0, }, VI6_DPR_NODE_RPF(idx) }
285 #define VSP1_ENTITY_ROUTE_UDS(idx) \
286 { VSP1_ENTITY_UDS, idx, VI6_DPR_UDS_ROUTE(idx), \
287 { VI6_DPR_NODE_UDS(idx) }, VI6_DPR_NODE_UDS(idx) }
289 #define VSP1_ENTITY_ROUTE_WPF(idx) \
290 { VSP1_ENTITY_WPF, idx, 0, \
291 { VI6_DPR_NODE_WPF(idx) }, VI6_DPR_NODE_WPF(idx) }
293 static const struct vsp1_route vsp1_routes
[] = {
294 { VSP1_ENTITY_BRU
, 0, VI6_DPR_BRU_ROUTE
,
295 { VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1),
296 VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3),
297 VI6_DPR_NODE_BRU_IN(4) }, VI6_DPR_NODE_BRU_OUT
},
298 VSP1_ENTITY_ROUTE(HSI
),
299 VSP1_ENTITY_ROUTE(HST
),
300 { VSP1_ENTITY_LIF
, 0, 0, { VI6_DPR_NODE_LIF
, }, VI6_DPR_NODE_LIF
},
301 VSP1_ENTITY_ROUTE(LUT
),
302 VSP1_ENTITY_ROUTE_RPF(0),
303 VSP1_ENTITY_ROUTE_RPF(1),
304 VSP1_ENTITY_ROUTE_RPF(2),
305 VSP1_ENTITY_ROUTE_RPF(3),
306 VSP1_ENTITY_ROUTE_RPF(4),
307 VSP1_ENTITY_ROUTE(SRU
),
308 VSP1_ENTITY_ROUTE_UDS(0),
309 VSP1_ENTITY_ROUTE_UDS(1),
310 VSP1_ENTITY_ROUTE_UDS(2),
311 VSP1_ENTITY_ROUTE_WPF(0),
312 VSP1_ENTITY_ROUTE_WPF(1),
313 VSP1_ENTITY_ROUTE_WPF(2),
314 VSP1_ENTITY_ROUTE_WPF(3),
317 int vsp1_entity_init(struct vsp1_device
*vsp1
, struct vsp1_entity
*entity
,
318 const char *name
, unsigned int num_pads
,
319 const struct v4l2_subdev_ops
*ops
)
321 struct v4l2_subdev
*subdev
;
325 for (i
= 0; i
< ARRAY_SIZE(vsp1_routes
); ++i
) {
326 if (vsp1_routes
[i
].type
== entity
->type
&&
327 vsp1_routes
[i
].index
== entity
->index
) {
328 entity
->route
= &vsp1_routes
[i
];
333 if (i
== ARRAY_SIZE(vsp1_routes
))
337 entity
->source_pad
= num_pads
- 1;
339 /* Allocate and initialize pads. */
340 entity
->pads
= devm_kzalloc(vsp1
->dev
, num_pads
* sizeof(*entity
->pads
),
342 if (entity
->pads
== NULL
)
345 for (i
= 0; i
< num_pads
- 1; ++i
)
346 entity
->pads
[i
].flags
= MEDIA_PAD_FL_SINK
;
348 entity
->pads
[num_pads
- 1].flags
= MEDIA_PAD_FL_SOURCE
;
350 /* Initialize the media entity. */
351 ret
= media_entity_pads_init(&entity
->subdev
.entity
, num_pads
,
356 /* Initialize the V4L2 subdev. */
357 subdev
= &entity
->subdev
;
358 v4l2_subdev_init(subdev
, ops
);
360 subdev
->entity
.ops
= &vsp1
->media_ops
;
361 subdev
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
363 snprintf(subdev
->name
, sizeof(subdev
->name
), "%s %s",
364 dev_name(vsp1
->dev
), name
);
366 vsp1_entity_init_cfg(subdev
, NULL
);
368 /* Allocate the pad configuration to store formats and selection
371 entity
->config
= v4l2_subdev_alloc_pad_config(&entity
->subdev
);
372 if (entity
->config
== NULL
) {
373 media_entity_cleanup(&entity
->subdev
.entity
);
380 void vsp1_entity_destroy(struct vsp1_entity
*entity
)
382 if (entity
->ops
&& entity
->ops
->destroy
)
383 entity
->ops
->destroy(entity
);
384 if (entity
->subdev
.ctrl_handler
)
385 v4l2_ctrl_handler_free(entity
->subdev
.ctrl_handler
);
386 v4l2_subdev_free_pad_config(entity
->config
);
387 media_entity_cleanup(&entity
->subdev
.entity
);