2 * vsp1_entity.c -- R-Car VSP1 Base Entity
4 * Copyright (C) 2013 Renesas 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-subdev.h>
21 #include "vsp1_entity.h"
23 /* -----------------------------------------------------------------------------
24 * V4L2 Subdevice Operations
27 struct v4l2_mbus_framefmt
*
28 vsp1_entity_get_pad_format(struct vsp1_entity
*entity
,
29 struct v4l2_subdev_fh
*fh
,
30 unsigned int pad
, u32 which
)
33 case V4L2_SUBDEV_FORMAT_TRY
:
34 return v4l2_subdev_get_try_format(fh
, pad
);
35 case V4L2_SUBDEV_FORMAT_ACTIVE
:
36 return &entity
->formats
[pad
];
43 * vsp1_entity_init_formats - Initialize formats on all pads
44 * @subdev: V4L2 subdevice
45 * @fh: V4L2 subdev file handle
47 * Initialize all pad formats with default values. If fh is not NULL, try
48 * formats are initialized on the file handle. Otherwise active formats are
49 * initialized on the device.
51 void vsp1_entity_init_formats(struct v4l2_subdev
*subdev
,
52 struct v4l2_subdev_fh
*fh
)
54 struct v4l2_subdev_format format
;
57 for (pad
= 0; pad
< subdev
->entity
.num_pads
- 1; ++pad
) {
58 memset(&format
, 0, sizeof(format
));
61 format
.which
= fh
? V4L2_SUBDEV_FORMAT_TRY
62 : V4L2_SUBDEV_FORMAT_ACTIVE
;
64 v4l2_subdev_call(subdev
, pad
, set_fmt
, fh
, &format
);
68 static int vsp1_entity_open(struct v4l2_subdev
*subdev
,
69 struct v4l2_subdev_fh
*fh
)
71 vsp1_entity_init_formats(subdev
, fh
);
76 const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops
= {
77 .open
= vsp1_entity_open
,
80 /* -----------------------------------------------------------------------------
84 static int vsp1_entity_link_setup(struct media_entity
*entity
,
85 const struct media_pad
*local
,
86 const struct media_pad
*remote
, u32 flags
)
88 struct vsp1_entity
*source
;
90 if (!(local
->flags
& MEDIA_PAD_FL_SOURCE
))
93 source
= container_of(local
->entity
, struct vsp1_entity
, subdev
.entity
);
98 if (flags
& MEDIA_LNK_FL_ENABLED
) {
101 source
->sink
= remote
->entity
;
109 const struct media_entity_operations vsp1_media_ops
= {
110 .link_setup
= vsp1_entity_link_setup
,
111 .link_validate
= v4l2_subdev_link_validate
,
114 /* -----------------------------------------------------------------------------
118 int vsp1_entity_init(struct vsp1_device
*vsp1
, struct vsp1_entity
*entity
,
119 unsigned int num_pads
)
121 static const struct {
125 { VI6_DPR_NODE_LIF
, 0 },
126 { VI6_DPR_NODE_RPF(0), VI6_DPR_RPF_ROUTE(0) },
127 { VI6_DPR_NODE_RPF(1), VI6_DPR_RPF_ROUTE(1) },
128 { VI6_DPR_NODE_RPF(2), VI6_DPR_RPF_ROUTE(2) },
129 { VI6_DPR_NODE_RPF(3), VI6_DPR_RPF_ROUTE(3) },
130 { VI6_DPR_NODE_RPF(4), VI6_DPR_RPF_ROUTE(4) },
131 { VI6_DPR_NODE_UDS(0), VI6_DPR_UDS_ROUTE(0) },
132 { VI6_DPR_NODE_UDS(1), VI6_DPR_UDS_ROUTE(1) },
133 { VI6_DPR_NODE_UDS(2), VI6_DPR_UDS_ROUTE(2) },
134 { VI6_DPR_NODE_WPF(0), 0 },
135 { VI6_DPR_NODE_WPF(1), 0 },
136 { VI6_DPR_NODE_WPF(2), 0 },
137 { VI6_DPR_NODE_WPF(3), 0 },
142 for (i
= 0; i
< ARRAY_SIZE(routes
); ++i
) {
143 if (routes
[i
].id
== entity
->id
) {
144 entity
->route
= routes
[i
].reg
;
149 if (i
== ARRAY_SIZE(routes
))
153 entity
->source_pad
= num_pads
- 1;
155 /* Allocate formats and pads. */
156 entity
->formats
= devm_kzalloc(vsp1
->dev
,
157 num_pads
* sizeof(*entity
->formats
),
159 if (entity
->formats
== NULL
)
162 entity
->pads
= devm_kzalloc(vsp1
->dev
, num_pads
* sizeof(*entity
->pads
),
164 if (entity
->pads
== NULL
)
167 /* Initialize pads. */
168 for (i
= 0; i
< num_pads
- 1; ++i
)
169 entity
->pads
[i
].flags
= MEDIA_PAD_FL_SINK
;
171 entity
->pads
[num_pads
- 1].flags
= MEDIA_PAD_FL_SOURCE
;
173 /* Initialize the media entity. */
174 return media_entity_init(&entity
->subdev
.entity
, num_pads
,
178 void vsp1_entity_destroy(struct vsp1_entity
*entity
)
180 media_entity_cleanup(&entity
->subdev
.entity
);