[media] v4l: vsp1: Remove unused module read functions
[deliverable/linux.git] / drivers / media / platform / vsp1 / vsp1_entity.c
CommitLineData
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"
22#include "vsp1_entity.h"
23
960de2cf
LP
24bool vsp1_entity_is_streaming(struct vsp1_entity *entity)
25{
adb8963f 26 unsigned long flags;
960de2cf
LP
27 bool streaming;
28
adb8963f 29 spin_lock_irqsave(&entity->lock, flags);
960de2cf 30 streaming = entity->streaming;
adb8963f 31 spin_unlock_irqrestore(&entity->lock, flags);
960de2cf
LP
32
33 return streaming;
34}
35
36int vsp1_entity_set_streaming(struct vsp1_entity *entity, bool streaming)
37{
adb8963f 38 unsigned long flags;
960de2cf
LP
39 int ret;
40
adb8963f 41 spin_lock_irqsave(&entity->lock, flags);
960de2cf 42 entity->streaming = streaming;
adb8963f 43 spin_unlock_irqrestore(&entity->lock, flags);
960de2cf
LP
44
45 if (!streaming)
46 return 0;
47
48 if (!entity->subdev.ctrl_handler)
49 return 0;
50
51 ret = v4l2_ctrl_handler_setup(entity->subdev.ctrl_handler);
52 if (ret < 0) {
adb8963f 53 spin_lock_irqsave(&entity->lock, flags);
960de2cf 54 entity->streaming = false;
adb8963f 55 spin_unlock_irqrestore(&entity->lock, flags);
960de2cf
LP
56 }
57
58 return ret;
59}
60
26e0ca22
LP
61/* -----------------------------------------------------------------------------
62 * V4L2 Subdevice Operations
63 */
64
65struct v4l2_mbus_framefmt *
66vsp1_entity_get_pad_format(struct vsp1_entity *entity,
f7234138 67 struct v4l2_subdev_pad_config *cfg,
26e0ca22
LP
68 unsigned int pad, u32 which)
69{
70 switch (which) {
71 case V4L2_SUBDEV_FORMAT_TRY:
f7234138 72 return v4l2_subdev_get_try_format(&entity->subdev, cfg, pad);
26e0ca22
LP
73 case V4L2_SUBDEV_FORMAT_ACTIVE:
74 return &entity->formats[pad];
75 default:
76 return NULL;
77 }
78}
79
80/*
81 * vsp1_entity_init_formats - Initialize formats on all pads
82 * @subdev: V4L2 subdevice
f7234138 83 * @cfg: V4L2 subdev pad configuration
26e0ca22 84 *
f7234138 85 * Initialize all pad formats with default values. If cfg is not NULL, try
26e0ca22
LP
86 * formats are initialized on the file handle. Otherwise active formats are
87 * initialized on the device.
88 */
89void vsp1_entity_init_formats(struct v4l2_subdev *subdev,
f7234138 90 struct v4l2_subdev_pad_config *cfg)
26e0ca22
LP
91{
92 struct v4l2_subdev_format format;
93 unsigned int pad;
94
95 for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
96 memset(&format, 0, sizeof(format));
97
98 format.pad = pad;
f7234138 99 format.which = cfg ? V4L2_SUBDEV_FORMAT_TRY
26e0ca22
LP
100 : V4L2_SUBDEV_FORMAT_ACTIVE;
101
f7234138 102 v4l2_subdev_call(subdev, pad, set_fmt, cfg, &format);
26e0ca22
LP
103 }
104}
105
106static int vsp1_entity_open(struct v4l2_subdev *subdev,
107 struct v4l2_subdev_fh *fh)
108{
f7234138 109 vsp1_entity_init_formats(subdev, fh->pad);
26e0ca22
LP
110
111 return 0;
112}
113
114const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops = {
115 .open = vsp1_entity_open,
116};
117
118/* -----------------------------------------------------------------------------
119 * Media Operations
120 */
121
122static int vsp1_entity_link_setup(struct media_entity *entity,
123 const struct media_pad *local,
124 const struct media_pad *remote, u32 flags)
125{
126 struct vsp1_entity *source;
127
128 if (!(local->flags & MEDIA_PAD_FL_SOURCE))
129 return 0;
130
131 source = container_of(local->entity, struct vsp1_entity, subdev.entity);
132
133 if (!source->route)
134 return 0;
135
136 if (flags & MEDIA_LNK_FL_ENABLED) {
137 if (source->sink)
138 return -EBUSY;
139 source->sink = remote->entity;
d9b45ed3 140 source->sink_pad = remote->index;
26e0ca22
LP
141 } else {
142 source->sink = NULL;
d9b45ed3 143 source->sink_pad = 0;
26e0ca22
LP
144 }
145
146 return 0;
147}
148
149const struct media_entity_operations vsp1_media_ops = {
150 .link_setup = vsp1_entity_link_setup,
151 .link_validate = v4l2_subdev_link_validate,
152};
153
154/* -----------------------------------------------------------------------------
155 * Initialization
156 */
157
d9b45ed3 158static const struct vsp1_route vsp1_routes[] = {
629bb6d4
LP
159 { VSP1_ENTITY_BRU, 0, VI6_DPR_BRU_ROUTE,
160 { VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1),
161 VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3), } },
d9b45ed3
LP
162 { VSP1_ENTITY_HSI, 0, VI6_DPR_HSI_ROUTE, { VI6_DPR_NODE_HSI, } },
163 { VSP1_ENTITY_HST, 0, VI6_DPR_HST_ROUTE, { VI6_DPR_NODE_HST, } },
164 { VSP1_ENTITY_LIF, 0, 0, { VI6_DPR_NODE_LIF, } },
165 { VSP1_ENTITY_LUT, 0, VI6_DPR_LUT_ROUTE, { VI6_DPR_NODE_LUT, } },
166 { VSP1_ENTITY_RPF, 0, VI6_DPR_RPF_ROUTE(0), { VI6_DPR_NODE_RPF(0), } },
167 { VSP1_ENTITY_RPF, 1, VI6_DPR_RPF_ROUTE(1), { VI6_DPR_NODE_RPF(1), } },
168 { VSP1_ENTITY_RPF, 2, VI6_DPR_RPF_ROUTE(2), { VI6_DPR_NODE_RPF(2), } },
169 { VSP1_ENTITY_RPF, 3, VI6_DPR_RPF_ROUTE(3), { VI6_DPR_NODE_RPF(3), } },
170 { VSP1_ENTITY_RPF, 4, VI6_DPR_RPF_ROUTE(4), { VI6_DPR_NODE_RPF(4), } },
171 { VSP1_ENTITY_SRU, 0, VI6_DPR_SRU_ROUTE, { VI6_DPR_NODE_SRU, } },
172 { VSP1_ENTITY_UDS, 0, VI6_DPR_UDS_ROUTE(0), { VI6_DPR_NODE_UDS(0), } },
173 { VSP1_ENTITY_UDS, 1, VI6_DPR_UDS_ROUTE(1), { VI6_DPR_NODE_UDS(1), } },
174 { VSP1_ENTITY_UDS, 2, VI6_DPR_UDS_ROUTE(2), { VI6_DPR_NODE_UDS(2), } },
175 { VSP1_ENTITY_WPF, 0, 0, { VI6_DPR_NODE_WPF(0), } },
176 { VSP1_ENTITY_WPF, 1, 0, { VI6_DPR_NODE_WPF(1), } },
177 { VSP1_ENTITY_WPF, 2, 0, { VI6_DPR_NODE_WPF(2), } },
178 { VSP1_ENTITY_WPF, 3, 0, { VI6_DPR_NODE_WPF(3), } },
179};
180
26e0ca22
LP
181int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
182 unsigned int num_pads)
183{
26e0ca22
LP
184 unsigned int i;
185
d9b45ed3
LP
186 for (i = 0; i < ARRAY_SIZE(vsp1_routes); ++i) {
187 if (vsp1_routes[i].type == entity->type &&
188 vsp1_routes[i].index == entity->index) {
189 entity->route = &vsp1_routes[i];
26e0ca22
LP
190 break;
191 }
192 }
193
d9b45ed3 194 if (i == ARRAY_SIZE(vsp1_routes))
26e0ca22
LP
195 return -EINVAL;
196
adb8963f 197 spin_lock_init(&entity->lock);
960de2cf 198
26e0ca22
LP
199 entity->vsp1 = vsp1;
200 entity->source_pad = num_pads - 1;
201
202 /* Allocate formats and pads. */
203 entity->formats = devm_kzalloc(vsp1->dev,
204 num_pads * sizeof(*entity->formats),
205 GFP_KERNEL);
206 if (entity->formats == NULL)
207 return -ENOMEM;
208
209 entity->pads = devm_kzalloc(vsp1->dev, num_pads * sizeof(*entity->pads),
210 GFP_KERNEL);
211 if (entity->pads == NULL)
212 return -ENOMEM;
213
214 /* Initialize pads. */
215 for (i = 0; i < num_pads - 1; ++i)
216 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
217
218 entity->pads[num_pads - 1].flags = MEDIA_PAD_FL_SOURCE;
219
220 /* Initialize the media entity. */
ab22e77c 221 return media_entity_pads_init(&entity->subdev.entity, num_pads,
18095107 222 entity->pads);
26e0ca22
LP
223}
224
225void vsp1_entity_destroy(struct vsp1_entity *entity)
226{
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}
This page took 0.137284 seconds and 5 git commands to generate.