]>
Commit | Line | Data |
---|---|---|
26e0ca22 LP |
1 | /* |
2 | * vsp1_entity.c -- R-Car VSP1 Base Entity | |
3 | * | |
8a1edc55 | 4 | * Copyright (C) 2013-2014 Renesas Electronics Corporation |
26e0ca22 LP |
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 | ||
14 | #include <linux/device.h> | |
15 | #include <linux/gfp.h> | |
16 | ||
17 | #include <media/media-entity.h> | |
a626e64e | 18 | #include <media/v4l2-ctrls.h> |
26e0ca22 LP |
19 | #include <media/v4l2-subdev.h> |
20 | ||
21 | #include "vsp1.h" | |
aa380ea0 | 22 | #include "vsp1_dl.h" |
26e0ca22 | 23 | #include "vsp1_entity.h" |
aa380ea0 LP |
24 | #include "vsp1_pipe.h" |
25 | ||
26 | void vsp1_mod_write(struct vsp1_entity *e, u32 reg, u32 data) | |
27 | { | |
28 | struct vsp1_pipeline *pipe = to_vsp1_pipeline(&e->subdev.entity); | |
29 | ||
351bbf99 | 30 | vsp1_dl_list_write(pipe->dl, reg, data); |
aa380ea0 | 31 | } |
26e0ca22 | 32 | |
665b693c LP |
33 | void vsp1_entity_route_setup(struct vsp1_entity *source) |
34 | { | |
35 | struct vsp1_entity *sink; | |
36 | ||
37 | if (source->route->reg == 0) | |
38 | return; | |
39 | ||
40 | sink = container_of(source->sink, struct vsp1_entity, subdev.entity); | |
1517b039 TS |
41 | vsp1_mod_write(source, source->route->reg, |
42 | sink->route->inputs[source->sink_pad]); | |
665b693c LP |
43 | } |
44 | ||
26e0ca22 LP |
45 | /* ----------------------------------------------------------------------------- |
46 | * V4L2 Subdevice Operations | |
47 | */ | |
48 | ||
49 | struct v4l2_mbus_framefmt * | |
50 | vsp1_entity_get_pad_format(struct vsp1_entity *entity, | |
f7234138 | 51 | struct v4l2_subdev_pad_config *cfg, |
26e0ca22 LP |
52 | unsigned int pad, u32 which) |
53 | { | |
54 | switch (which) { | |
55 | case V4L2_SUBDEV_FORMAT_TRY: | |
f7234138 | 56 | return v4l2_subdev_get_try_format(&entity->subdev, cfg, pad); |
26e0ca22 LP |
57 | case V4L2_SUBDEV_FORMAT_ACTIVE: |
58 | return &entity->formats[pad]; | |
59 | default: | |
60 | return NULL; | |
61 | } | |
62 | } | |
63 | ||
64 | /* | |
65 | * vsp1_entity_init_formats - Initialize formats on all pads | |
66 | * @subdev: V4L2 subdevice | |
f7234138 | 67 | * @cfg: V4L2 subdev pad configuration |
26e0ca22 | 68 | * |
f7234138 | 69 | * Initialize all pad formats with default values. If cfg is not NULL, try |
26e0ca22 LP |
70 | * formats are initialized on the file handle. Otherwise active formats are |
71 | * initialized on the device. | |
72 | */ | |
823329df LP |
73 | static void vsp1_entity_init_formats(struct v4l2_subdev *subdev, |
74 | struct v4l2_subdev_pad_config *cfg) | |
26e0ca22 LP |
75 | { |
76 | struct v4l2_subdev_format format; | |
77 | unsigned int pad; | |
78 | ||
79 | for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) { | |
80 | memset(&format, 0, sizeof(format)); | |
81 | ||
82 | format.pad = pad; | |
f7234138 | 83 | format.which = cfg ? V4L2_SUBDEV_FORMAT_TRY |
26e0ca22 LP |
84 | : V4L2_SUBDEV_FORMAT_ACTIVE; |
85 | ||
f7234138 | 86 | v4l2_subdev_call(subdev, pad, set_fmt, cfg, &format); |
26e0ca22 LP |
87 | } |
88 | } | |
89 | ||
90 | static int vsp1_entity_open(struct v4l2_subdev *subdev, | |
91 | struct v4l2_subdev_fh *fh) | |
92 | { | |
f7234138 | 93 | vsp1_entity_init_formats(subdev, fh->pad); |
26e0ca22 LP |
94 | |
95 | return 0; | |
96 | } | |
97 | ||
98 | const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops = { | |
99 | .open = vsp1_entity_open, | |
100 | }; | |
101 | ||
102 | /* ----------------------------------------------------------------------------- | |
103 | * Media Operations | |
104 | */ | |
105 | ||
babca007 LP |
106 | int vsp1_entity_link_setup(struct media_entity *entity, |
107 | const struct media_pad *local, | |
108 | const struct media_pad *remote, u32 flags) | |
26e0ca22 LP |
109 | { |
110 | struct vsp1_entity *source; | |
111 | ||
112 | if (!(local->flags & MEDIA_PAD_FL_SOURCE)) | |
113 | return 0; | |
114 | ||
115 | source = container_of(local->entity, struct vsp1_entity, subdev.entity); | |
116 | ||
117 | if (!source->route) | |
118 | return 0; | |
119 | ||
120 | if (flags & MEDIA_LNK_FL_ENABLED) { | |
121 | if (source->sink) | |
122 | return -EBUSY; | |
123 | source->sink = remote->entity; | |
d9b45ed3 | 124 | source->sink_pad = remote->index; |
26e0ca22 LP |
125 | } else { |
126 | source->sink = NULL; | |
d9b45ed3 | 127 | source->sink_pad = 0; |
26e0ca22 LP |
128 | } |
129 | ||
130 | return 0; | |
131 | } | |
132 | ||
26e0ca22 LP |
133 | /* ----------------------------------------------------------------------------- |
134 | * Initialization | |
135 | */ | |
136 | ||
d9b45ed3 | 137 | static const struct vsp1_route vsp1_routes[] = { |
629bb6d4 LP |
138 | { VSP1_ENTITY_BRU, 0, VI6_DPR_BRU_ROUTE, |
139 | { VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1), | |
7f2d50f8 LP |
140 | VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3), |
141 | VI6_DPR_NODE_BRU_IN(4) } }, | |
d9b45ed3 LP |
142 | { VSP1_ENTITY_HSI, 0, VI6_DPR_HSI_ROUTE, { VI6_DPR_NODE_HSI, } }, |
143 | { VSP1_ENTITY_HST, 0, VI6_DPR_HST_ROUTE, { VI6_DPR_NODE_HST, } }, | |
144 | { VSP1_ENTITY_LIF, 0, 0, { VI6_DPR_NODE_LIF, } }, | |
145 | { VSP1_ENTITY_LUT, 0, VI6_DPR_LUT_ROUTE, { VI6_DPR_NODE_LUT, } }, | |
146 | { VSP1_ENTITY_RPF, 0, VI6_DPR_RPF_ROUTE(0), { VI6_DPR_NODE_RPF(0), } }, | |
147 | { VSP1_ENTITY_RPF, 1, VI6_DPR_RPF_ROUTE(1), { VI6_DPR_NODE_RPF(1), } }, | |
148 | { VSP1_ENTITY_RPF, 2, VI6_DPR_RPF_ROUTE(2), { VI6_DPR_NODE_RPF(2), } }, | |
149 | { VSP1_ENTITY_RPF, 3, VI6_DPR_RPF_ROUTE(3), { VI6_DPR_NODE_RPF(3), } }, | |
150 | { VSP1_ENTITY_RPF, 4, VI6_DPR_RPF_ROUTE(4), { VI6_DPR_NODE_RPF(4), } }, | |
151 | { VSP1_ENTITY_SRU, 0, VI6_DPR_SRU_ROUTE, { VI6_DPR_NODE_SRU, } }, | |
152 | { VSP1_ENTITY_UDS, 0, VI6_DPR_UDS_ROUTE(0), { VI6_DPR_NODE_UDS(0), } }, | |
153 | { VSP1_ENTITY_UDS, 1, VI6_DPR_UDS_ROUTE(1), { VI6_DPR_NODE_UDS(1), } }, | |
154 | { VSP1_ENTITY_UDS, 2, VI6_DPR_UDS_ROUTE(2), { VI6_DPR_NODE_UDS(2), } }, | |
155 | { VSP1_ENTITY_WPF, 0, 0, { VI6_DPR_NODE_WPF(0), } }, | |
156 | { VSP1_ENTITY_WPF, 1, 0, { VI6_DPR_NODE_WPF(1), } }, | |
157 | { VSP1_ENTITY_WPF, 2, 0, { VI6_DPR_NODE_WPF(2), } }, | |
158 | { VSP1_ENTITY_WPF, 3, 0, { VI6_DPR_NODE_WPF(3), } }, | |
159 | }; | |
160 | ||
26e0ca22 | 161 | int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, |
823329df LP |
162 | const char *name, unsigned int num_pads, |
163 | const struct v4l2_subdev_ops *ops) | |
26e0ca22 | 164 | { |
823329df | 165 | struct v4l2_subdev *subdev; |
26e0ca22 | 166 | unsigned int i; |
823329df | 167 | int ret; |
26e0ca22 | 168 | |
d9b45ed3 LP |
169 | for (i = 0; i < ARRAY_SIZE(vsp1_routes); ++i) { |
170 | if (vsp1_routes[i].type == entity->type && | |
171 | vsp1_routes[i].index == entity->index) { | |
172 | entity->route = &vsp1_routes[i]; | |
26e0ca22 LP |
173 | break; |
174 | } | |
175 | } | |
176 | ||
d9b45ed3 | 177 | if (i == ARRAY_SIZE(vsp1_routes)) |
26e0ca22 LP |
178 | return -EINVAL; |
179 | ||
180 | entity->vsp1 = vsp1; | |
181 | entity->source_pad = num_pads - 1; | |
182 | ||
183 | /* Allocate formats and pads. */ | |
184 | entity->formats = devm_kzalloc(vsp1->dev, | |
185 | num_pads * sizeof(*entity->formats), | |
186 | GFP_KERNEL); | |
187 | if (entity->formats == NULL) | |
188 | return -ENOMEM; | |
189 | ||
190 | entity->pads = devm_kzalloc(vsp1->dev, num_pads * sizeof(*entity->pads), | |
191 | GFP_KERNEL); | |
192 | if (entity->pads == NULL) | |
193 | return -ENOMEM; | |
194 | ||
195 | /* Initialize pads. */ | |
196 | for (i = 0; i < num_pads - 1; ++i) | |
197 | entity->pads[i].flags = MEDIA_PAD_FL_SINK; | |
198 | ||
199 | entity->pads[num_pads - 1].flags = MEDIA_PAD_FL_SOURCE; | |
200 | ||
201 | /* Initialize the media entity. */ | |
823329df LP |
202 | ret = media_entity_pads_init(&entity->subdev.entity, num_pads, |
203 | entity->pads); | |
204 | if (ret < 0) | |
205 | return ret; | |
206 | ||
207 | /* Initialize the V4L2 subdev. */ | |
208 | subdev = &entity->subdev; | |
209 | v4l2_subdev_init(subdev, ops); | |
210 | ||
211 | subdev->entity.ops = &vsp1->media_ops; | |
212 | subdev->internal_ops = &vsp1_subdev_internal_ops; | |
213 | subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; | |
214 | ||
215 | snprintf(subdev->name, sizeof(subdev->name), "%s %s", | |
216 | dev_name(vsp1->dev), name); | |
217 | ||
218 | vsp1_entity_init_formats(subdev, NULL); | |
219 | ||
220 | return 0; | |
26e0ca22 LP |
221 | } |
222 | ||
223 | void vsp1_entity_destroy(struct vsp1_entity *entity) | |
224 | { | |
52434534 LP |
225 | if (entity->ops && entity->ops->destroy) |
226 | entity->ops->destroy(entity); | |
a626e64e LP |
227 | if (entity->subdev.ctrl_handler) |
228 | v4l2_ctrl_handler_free(entity->subdev.ctrl_handler); | |
26e0ca22 LP |
229 | media_entity_cleanup(&entity->subdev.entity); |
230 | } |