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"
24 #include "vsp1_pipe.h"
26 void vsp1_mod_write(struct vsp1_entity
*e
, u32 reg
, u32 data
)
28 struct vsp1_pipeline
*pipe
= to_vsp1_pipeline(&e
->subdev
.entity
);
30 vsp1_dl_list_write(pipe
->dl
, reg
, data
);
33 void vsp1_entity_route_setup(struct vsp1_entity
*source
)
35 struct vsp1_entity
*sink
;
37 if (source
->route
->reg
== 0)
40 sink
= container_of(source
->sink
, struct vsp1_entity
, subdev
.entity
);
41 vsp1_mod_write(source
, source
->route
->reg
,
42 sink
->route
->inputs
[source
->sink_pad
]);
45 /* -----------------------------------------------------------------------------
46 * V4L2 Subdevice Operations
50 * vsp1_entity_get_pad_config - Get the pad configuration for an entity
52 * @cfg: the TRY pad configuration
53 * @which: configuration selector (ACTIVE or TRY)
55 * Return the pad configuration requested by the which argument. The TRY
56 * configuration is passed explicitly to the function through the cfg argument
57 * and simply returned when requested. The ACTIVE configuration comes from the
60 struct v4l2_subdev_pad_config
*
61 vsp1_entity_get_pad_config(struct vsp1_entity
*entity
,
62 struct v4l2_subdev_pad_config
*cfg
,
63 enum v4l2_subdev_format_whence which
)
66 case V4L2_SUBDEV_FORMAT_ACTIVE
:
67 return entity
->config
;
68 case V4L2_SUBDEV_FORMAT_TRY
:
75 * vsp1_entity_get_pad_format - Get a pad format from storage for an entity
77 * @cfg: the configuration storage
78 * @pad: the pad number
80 * Return the format stored in the given configuration for an entity's pad. The
81 * configuration can be an ACTIVE or TRY configuration.
83 struct v4l2_mbus_framefmt
*
84 vsp1_entity_get_pad_format(struct vsp1_entity
*entity
,
85 struct v4l2_subdev_pad_config
*cfg
,
88 return v4l2_subdev_get_try_format(&entity
->subdev
, cfg
, pad
);
92 vsp1_entity_get_pad_compose(struct vsp1_entity
*entity
,
93 struct v4l2_subdev_pad_config
*cfg
,
96 return v4l2_subdev_get_try_compose(&entity
->subdev
, cfg
, pad
);
100 * vsp1_entity_init_cfg - Initialize formats on all pads
101 * @subdev: V4L2 subdevice
102 * @cfg: V4L2 subdev pad configuration
104 * Initialize all pad formats with default values in the given pad config. This
105 * function can be used as a handler for the subdev pad::init_cfg operation.
107 int vsp1_entity_init_cfg(struct v4l2_subdev
*subdev
,
108 struct v4l2_subdev_pad_config
*cfg
)
110 struct v4l2_subdev_format format
;
113 for (pad
= 0; pad
< subdev
->entity
.num_pads
- 1; ++pad
) {
114 memset(&format
, 0, sizeof(format
));
117 format
.which
= cfg
? V4L2_SUBDEV_FORMAT_TRY
118 : V4L2_SUBDEV_FORMAT_ACTIVE
;
120 v4l2_subdev_call(subdev
, pad
, set_fmt
, cfg
, &format
);
126 /* -----------------------------------------------------------------------------
130 int vsp1_entity_link_setup(struct media_entity
*entity
,
131 const struct media_pad
*local
,
132 const struct media_pad
*remote
, u32 flags
)
134 struct vsp1_entity
*source
;
136 if (!(local
->flags
& MEDIA_PAD_FL_SOURCE
))
139 source
= container_of(local
->entity
, struct vsp1_entity
, subdev
.entity
);
144 if (flags
& MEDIA_LNK_FL_ENABLED
) {
147 source
->sink
= remote
->entity
;
148 source
->sink_pad
= remote
->index
;
151 source
->sink_pad
= 0;
157 /* -----------------------------------------------------------------------------
161 static const struct vsp1_route vsp1_routes
[] = {
162 { VSP1_ENTITY_BRU
, 0, VI6_DPR_BRU_ROUTE
,
163 { VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1),
164 VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3),
165 VI6_DPR_NODE_BRU_IN(4) } },
166 { VSP1_ENTITY_HSI
, 0, VI6_DPR_HSI_ROUTE
, { VI6_DPR_NODE_HSI
, } },
167 { VSP1_ENTITY_HST
, 0, VI6_DPR_HST_ROUTE
, { VI6_DPR_NODE_HST
, } },
168 { VSP1_ENTITY_LIF
, 0, 0, { VI6_DPR_NODE_LIF
, } },
169 { VSP1_ENTITY_LUT
, 0, VI6_DPR_LUT_ROUTE
, { VI6_DPR_NODE_LUT
, } },
170 { VSP1_ENTITY_RPF
, 0, VI6_DPR_RPF_ROUTE(0), { VI6_DPR_NODE_RPF(0), } },
171 { VSP1_ENTITY_RPF
, 1, VI6_DPR_RPF_ROUTE(1), { VI6_DPR_NODE_RPF(1), } },
172 { VSP1_ENTITY_RPF
, 2, VI6_DPR_RPF_ROUTE(2), { VI6_DPR_NODE_RPF(2), } },
173 { VSP1_ENTITY_RPF
, 3, VI6_DPR_RPF_ROUTE(3), { VI6_DPR_NODE_RPF(3), } },
174 { VSP1_ENTITY_RPF
, 4, VI6_DPR_RPF_ROUTE(4), { VI6_DPR_NODE_RPF(4), } },
175 { VSP1_ENTITY_SRU
, 0, VI6_DPR_SRU_ROUTE
, { VI6_DPR_NODE_SRU
, } },
176 { VSP1_ENTITY_UDS
, 0, VI6_DPR_UDS_ROUTE(0), { VI6_DPR_NODE_UDS(0), } },
177 { VSP1_ENTITY_UDS
, 1, VI6_DPR_UDS_ROUTE(1), { VI6_DPR_NODE_UDS(1), } },
178 { VSP1_ENTITY_UDS
, 2, VI6_DPR_UDS_ROUTE(2), { VI6_DPR_NODE_UDS(2), } },
179 { VSP1_ENTITY_WPF
, 0, 0, { VI6_DPR_NODE_WPF(0), } },
180 { VSP1_ENTITY_WPF
, 1, 0, { VI6_DPR_NODE_WPF(1), } },
181 { VSP1_ENTITY_WPF
, 2, 0, { VI6_DPR_NODE_WPF(2), } },
182 { VSP1_ENTITY_WPF
, 3, 0, { VI6_DPR_NODE_WPF(3), } },
185 int vsp1_entity_init(struct vsp1_device
*vsp1
, struct vsp1_entity
*entity
,
186 const char *name
, unsigned int num_pads
,
187 const struct v4l2_subdev_ops
*ops
)
189 struct v4l2_subdev
*subdev
;
193 for (i
= 0; i
< ARRAY_SIZE(vsp1_routes
); ++i
) {
194 if (vsp1_routes
[i
].type
== entity
->type
&&
195 vsp1_routes
[i
].index
== entity
->index
) {
196 entity
->route
= &vsp1_routes
[i
];
201 if (i
== ARRAY_SIZE(vsp1_routes
))
205 entity
->source_pad
= num_pads
- 1;
207 /* Allocate and initialize pads. */
208 entity
->pads
= devm_kzalloc(vsp1
->dev
, num_pads
* sizeof(*entity
->pads
),
210 if (entity
->pads
== NULL
)
213 for (i
= 0; i
< num_pads
- 1; ++i
)
214 entity
->pads
[i
].flags
= MEDIA_PAD_FL_SINK
;
216 entity
->pads
[num_pads
- 1].flags
= MEDIA_PAD_FL_SOURCE
;
218 /* Initialize the media entity. */
219 ret
= media_entity_pads_init(&entity
->subdev
.entity
, num_pads
,
224 /* Initialize the V4L2 subdev. */
225 subdev
= &entity
->subdev
;
226 v4l2_subdev_init(subdev
, ops
);
228 subdev
->entity
.ops
= &vsp1
->media_ops
;
229 subdev
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
231 snprintf(subdev
->name
, sizeof(subdev
->name
), "%s %s",
232 dev_name(vsp1
->dev
), name
);
234 vsp1_entity_init_cfg(subdev
, NULL
);
236 /* Allocate the pad configuration to store formats and selection
239 entity
->config
= v4l2_subdev_alloc_pad_config(&entity
->subdev
);
240 if (entity
->config
== NULL
) {
241 media_entity_cleanup(&entity
->subdev
.entity
);
248 void vsp1_entity_destroy(struct vsp1_entity
*entity
)
250 if (entity
->ops
&& entity
->ops
->destroy
)
251 entity
->ops
->destroy(entity
);
252 if (entity
->subdev
.ctrl_handler
)
253 v4l2_ctrl_handler_free(entity
->subdev
.ctrl_handler
);
254 v4l2_subdev_free_pad_config(entity
->config
);
255 media_entity_cleanup(&entity
->subdev
.entity
);