mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / media / platform / vsp1 / vsp1_entity.c
blob9028f9d524f4b3e42e9e5d84243bb29df8023f9f
1 /*
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>
20 #include "vsp1.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)
32 switch (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];
37 default:
38 return NULL;
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;
55 unsigned int pad;
57 for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
58 memset(&format, 0, sizeof(format));
60 format.pad = pad;
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);
73 return 0;
76 const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops = {
77 .open = vsp1_entity_open,
80 /* -----------------------------------------------------------------------------
81 * Media Operations
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))
91 return 0;
93 source = container_of(local->entity, struct vsp1_entity, subdev.entity);
95 if (!source->route)
96 return 0;
98 if (flags & MEDIA_LNK_FL_ENABLED) {
99 if (source->sink)
100 return -EBUSY;
101 source->sink = remote->entity;
102 } else {
103 source->sink = NULL;
106 return 0;
109 const struct media_entity_operations vsp1_media_ops = {
110 .link_setup = vsp1_entity_link_setup,
111 .link_validate = v4l2_subdev_link_validate,
114 /* -----------------------------------------------------------------------------
115 * Initialization
118 int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
119 unsigned int num_pads)
121 static const struct {
122 unsigned int id;
123 unsigned int reg;
124 } routes[] = {
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 },
140 unsigned int i;
142 for (i = 0; i < ARRAY_SIZE(routes); ++i) {
143 if (routes[i].id == entity->id) {
144 entity->route = routes[i].reg;
145 break;
149 if (i == ARRAY_SIZE(routes))
150 return -EINVAL;
152 entity->vsp1 = vsp1;
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),
158 GFP_KERNEL);
159 if (entity->formats == NULL)
160 return -ENOMEM;
162 entity->pads = devm_kzalloc(vsp1->dev, num_pads * sizeof(*entity->pads),
163 GFP_KERNEL);
164 if (entity->pads == NULL)
165 return -ENOMEM;
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,
175 entity->pads, 0);
178 void vsp1_entity_destroy(struct vsp1_entity *entity)
180 media_entity_cleanup(&entity->subdev.entity);