This source file includes following definitions.
- xvip_get_format_by_code
- xvip_get_format_by_fourcc
- xvip_of_get_format
- xvip_set_format_size
- xvip_clr_or_set
- xvip_clr_and_set
- xvip_init_resources
- xvip_cleanup_resources
- xvip_enum_mbus_code
- xvip_enum_frame_size
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/clk.h>
13 #include <linux/export.h>
14 #include <linux/kernel.h>
15 #include <linux/of.h>
16 #include <linux/platform_device.h>
17
18 #include <dt-bindings/media/xilinx-vip.h>
19
20 #include "xilinx-vip.h"
21
22
23
24
25
26 static const struct xvip_video_format xvip_video_formats[] = {
27 { XVIP_VF_YUV_422, 8, NULL, MEDIA_BUS_FMT_UYVY8_1X16,
28 2, V4L2_PIX_FMT_YUYV },
29 { XVIP_VF_YUV_444, 8, NULL, MEDIA_BUS_FMT_VUY8_1X24,
30 3, V4L2_PIX_FMT_YUV444 },
31 { XVIP_VF_RBG, 8, NULL, MEDIA_BUS_FMT_RBG888_1X24,
32 3, 0 },
33 { XVIP_VF_MONO_SENSOR, 8, "mono", MEDIA_BUS_FMT_Y8_1X8,
34 1, V4L2_PIX_FMT_GREY },
35 { XVIP_VF_MONO_SENSOR, 8, "rggb", MEDIA_BUS_FMT_SRGGB8_1X8,
36 1, V4L2_PIX_FMT_SRGGB8 },
37 { XVIP_VF_MONO_SENSOR, 8, "grbg", MEDIA_BUS_FMT_SGRBG8_1X8,
38 1, V4L2_PIX_FMT_SGRBG8 },
39 { XVIP_VF_MONO_SENSOR, 8, "gbrg", MEDIA_BUS_FMT_SGBRG8_1X8,
40 1, V4L2_PIX_FMT_SGBRG8 },
41 { XVIP_VF_MONO_SENSOR, 8, "bggr", MEDIA_BUS_FMT_SBGGR8_1X8,
42 1, V4L2_PIX_FMT_SBGGR8 },
43 };
44
45
46
47
48
49
50
51
52
53 const struct xvip_video_format *xvip_get_format_by_code(unsigned int code)
54 {
55 unsigned int i;
56
57 for (i = 0; i < ARRAY_SIZE(xvip_video_formats); ++i) {
58 const struct xvip_video_format *format = &xvip_video_formats[i];
59
60 if (format->code == code)
61 return format;
62 }
63
64 return ERR_PTR(-EINVAL);
65 }
66 EXPORT_SYMBOL_GPL(xvip_get_format_by_code);
67
68
69
70
71
72
73
74
75
76 const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc)
77 {
78 unsigned int i;
79
80 for (i = 0; i < ARRAY_SIZE(xvip_video_formats); ++i) {
81 const struct xvip_video_format *format = &xvip_video_formats[i];
82
83 if (format->fourcc == fourcc)
84 return format;
85 }
86
87 return ERR_PTR(-EINVAL);
88 }
89 EXPORT_SYMBOL_GPL(xvip_get_format_by_fourcc);
90
91
92
93
94
95
96
97
98
99
100
101
102 const struct xvip_video_format *xvip_of_get_format(struct device_node *node)
103 {
104 const char *pattern = "mono";
105 unsigned int vf_code;
106 unsigned int i;
107 u32 width;
108 int ret;
109
110 ret = of_property_read_u32(node, "xlnx,video-format", &vf_code);
111 if (ret < 0)
112 return ERR_PTR(ret);
113
114 ret = of_property_read_u32(node, "xlnx,video-width", &width);
115 if (ret < 0)
116 return ERR_PTR(ret);
117
118 if (vf_code == XVIP_VF_MONO_SENSOR)
119 of_property_read_string(node, "xlnx,cfa-pattern", &pattern);
120
121 for (i = 0; i < ARRAY_SIZE(xvip_video_formats); ++i) {
122 const struct xvip_video_format *format = &xvip_video_formats[i];
123
124 if (format->vf_code != vf_code || format->width != width)
125 continue;
126
127 if (vf_code == XVIP_VF_MONO_SENSOR &&
128 strcmp(pattern, format->pattern))
129 continue;
130
131 return format;
132 }
133
134 return ERR_PTR(-EINVAL);
135 }
136 EXPORT_SYMBOL_GPL(xvip_of_get_format);
137
138
139
140
141
142
143
144
145
146
147 void xvip_set_format_size(struct v4l2_mbus_framefmt *format,
148 const struct v4l2_subdev_format *fmt)
149 {
150 format->width = clamp_t(unsigned int, fmt->format.width,
151 XVIP_MIN_WIDTH, XVIP_MAX_WIDTH);
152 format->height = clamp_t(unsigned int, fmt->format.height,
153 XVIP_MIN_HEIGHT, XVIP_MAX_HEIGHT);
154 }
155 EXPORT_SYMBOL_GPL(xvip_set_format_size);
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 void xvip_clr_or_set(struct xvip_device *xvip, u32 addr, u32 mask, bool set)
175 {
176 u32 reg;
177
178 reg = xvip_read(xvip, addr);
179 reg = set ? reg | mask : reg & ~mask;
180 xvip_write(xvip, addr, reg);
181 }
182 EXPORT_SYMBOL_GPL(xvip_clr_or_set);
183
184
185
186
187
188
189
190
191
192
193
194 void xvip_clr_and_set(struct xvip_device *xvip, u32 addr, u32 clr, u32 set)
195 {
196 u32 reg;
197
198 reg = xvip_read(xvip, addr);
199 reg &= ~clr;
200 reg |= set;
201 xvip_write(xvip, addr, reg);
202 }
203 EXPORT_SYMBOL_GPL(xvip_clr_and_set);
204
205 int xvip_init_resources(struct xvip_device *xvip)
206 {
207 struct platform_device *pdev = to_platform_device(xvip->dev);
208 struct resource *res;
209
210 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
211 xvip->iomem = devm_ioremap_resource(xvip->dev, res);
212 if (IS_ERR(xvip->iomem))
213 return PTR_ERR(xvip->iomem);
214
215 xvip->clk = devm_clk_get(xvip->dev, NULL);
216 if (IS_ERR(xvip->clk))
217 return PTR_ERR(xvip->clk);
218
219 clk_prepare_enable(xvip->clk);
220 return 0;
221 }
222 EXPORT_SYMBOL_GPL(xvip_init_resources);
223
224 void xvip_cleanup_resources(struct xvip_device *xvip)
225 {
226 clk_disable_unprepare(xvip->clk);
227 }
228 EXPORT_SYMBOL_GPL(xvip_cleanup_resources);
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 int xvip_enum_mbus_code(struct v4l2_subdev *subdev,
249 struct v4l2_subdev_pad_config *cfg,
250 struct v4l2_subdev_mbus_code_enum *code)
251 {
252 struct v4l2_mbus_framefmt *format;
253
254
255
256
257 if (code->which == V4L2_SUBDEV_FORMAT_ACTIVE)
258 return -EINVAL;
259
260 if (code->index)
261 return -EINVAL;
262
263 format = v4l2_subdev_get_try_format(subdev, cfg, code->pad);
264
265 code->code = format->code;
266
267 return 0;
268 }
269 EXPORT_SYMBOL_GPL(xvip_enum_mbus_code);
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 int xvip_enum_frame_size(struct v4l2_subdev *subdev,
287 struct v4l2_subdev_pad_config *cfg,
288 struct v4l2_subdev_frame_size_enum *fse)
289 {
290 struct v4l2_mbus_framefmt *format;
291
292
293
294
295 if (fse->which == V4L2_SUBDEV_FORMAT_ACTIVE)
296 return -EINVAL;
297
298 format = v4l2_subdev_get_try_format(subdev, cfg, fse->pad);
299
300 if (fse->index || fse->code != format->code)
301 return -EINVAL;
302
303 if (fse->pad == XVIP_PAD_SINK) {
304 fse->min_width = XVIP_MIN_WIDTH;
305 fse->max_width = XVIP_MAX_WIDTH;
306 fse->min_height = XVIP_MIN_HEIGHT;
307 fse->max_height = XVIP_MAX_HEIGHT;
308 } else {
309
310
311
312 fse->min_width = format->width;
313 fse->max_width = format->width;
314 fse->min_height = format->height;
315 fse->max_height = format->height;
316 }
317
318 return 0;
319 }
320 EXPORT_SYMBOL_GPL(xvip_enum_frame_size);