[media] vivid: add new format fields
[deliverable/linux.git] / drivers / media / platform / vivid / vivid-vid-common.c
CommitLineData
ef834f78
HV
1/*
2 * vivid-vid-common.c - common video support functions.
3 *
4 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5 *
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20#include <linux/errno.h>
21#include <linux/kernel.h>
22#include <linux/sched.h>
23#include <linux/videodev2.h>
24#include <linux/v4l2-dv-timings.h>
25#include <media/v4l2-common.h>
26#include <media/v4l2-event.h>
27#include <media/v4l2-dv-timings.h>
28
29#include "vivid-core.h"
30#include "vivid-vid-common.h"
31
32const struct v4l2_dv_timings_cap vivid_dv_timings_cap = {
33 .type = V4L2_DV_BT_656_1120,
34 /* keep this initialization for compatibility with GCC < 4.4.6 */
35 .reserved = { 0 },
36 V4L2_INIT_BT_TIMINGS(0, MAX_WIDTH, 0, MAX_HEIGHT, 25000000, 600000000,
37 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT,
38 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_INTERLACED)
39};
40
41/* ------------------------------------------------------------------
42 Basic structures
43 ------------------------------------------------------------------*/
44
45struct vivid_fmt vivid_formats[] = {
46 {
47 .name = "4:2:2, packed, YUYV",
48 .fourcc = V4L2_PIX_FMT_YUYV,
96c76efa
HV
49 .vdownsampling = { 1 },
50 .bit_depth = { 16 },
ef834f78
HV
51 .is_yuv = true,
52 .planes = 1,
96c76efa 53 .buffers = 1,
ef834f78
HV
54 .data_offset = { PLANE0_DATA_OFFSET, 0 },
55 },
56 {
57 .name = "4:2:2, packed, UYVY",
58 .fourcc = V4L2_PIX_FMT_UYVY,
96c76efa
HV
59 .vdownsampling = { 1 },
60 .bit_depth = { 16 },
ef834f78
HV
61 .is_yuv = true,
62 .planes = 1,
96c76efa 63 .buffers = 1,
ef834f78
HV
64 },
65 {
66 .name = "4:2:2, packed, YVYU",
67 .fourcc = V4L2_PIX_FMT_YVYU,
96c76efa
HV
68 .vdownsampling = { 1 },
69 .bit_depth = { 16 },
ef834f78
HV
70 .is_yuv = true,
71 .planes = 1,
96c76efa 72 .buffers = 1,
ef834f78
HV
73 },
74 {
75 .name = "4:2:2, packed, VYUY",
76 .fourcc = V4L2_PIX_FMT_VYUY,
96c76efa
HV
77 .vdownsampling = { 1 },
78 .bit_depth = { 16 },
ef834f78
HV
79 .is_yuv = true,
80 .planes = 1,
96c76efa 81 .buffers = 1,
ef834f78
HV
82 },
83 {
84 .name = "RGB565 (LE)",
85 .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */
96c76efa
HV
86 .vdownsampling = { 1 },
87 .bit_depth = { 16 },
ef834f78 88 .planes = 1,
96c76efa 89 .buffers = 1,
ef834f78
HV
90 .can_do_overlay = true,
91 },
92 {
93 .name = "RGB565 (BE)",
94 .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
96c76efa
HV
95 .vdownsampling = { 1 },
96 .bit_depth = { 16 },
ef834f78 97 .planes = 1,
96c76efa 98 .buffers = 1,
ef834f78
HV
99 .can_do_overlay = true,
100 },
101 {
102 .name = "RGB555 (LE)",
103 .fourcc = V4L2_PIX_FMT_RGB555, /* gggbbbbb arrrrrgg */
96c76efa
HV
104 .vdownsampling = { 1 },
105 .bit_depth = { 16 },
ef834f78 106 .planes = 1,
96c76efa 107 .buffers = 1,
ef834f78
HV
108 .can_do_overlay = true,
109 },
110 {
111 .name = "XRGB555 (LE)",
112 .fourcc = V4L2_PIX_FMT_XRGB555, /* gggbbbbb arrrrrgg */
96c76efa
HV
113 .vdownsampling = { 1 },
114 .bit_depth = { 16 },
ef834f78 115 .planes = 1,
96c76efa 116 .buffers = 1,
ef834f78
HV
117 .can_do_overlay = true,
118 },
119 {
120 .name = "ARGB555 (LE)",
121 .fourcc = V4L2_PIX_FMT_ARGB555, /* gggbbbbb arrrrrgg */
96c76efa
HV
122 .vdownsampling = { 1 },
123 .bit_depth = { 16 },
ef834f78 124 .planes = 1,
96c76efa 125 .buffers = 1,
ef834f78
HV
126 .can_do_overlay = true,
127 .alpha_mask = 0x8000,
128 },
129 {
130 .name = "RGB555 (BE)",
131 .fourcc = V4L2_PIX_FMT_RGB555X, /* arrrrrgg gggbbbbb */
96c76efa
HV
132 .vdownsampling = { 1 },
133 .bit_depth = { 16 },
ef834f78 134 .planes = 1,
96c76efa 135 .buffers = 1,
ef834f78
HV
136 .can_do_overlay = true,
137 },
138 {
139 .name = "RGB24 (LE)",
140 .fourcc = V4L2_PIX_FMT_RGB24, /* rgb */
96c76efa
HV
141 .vdownsampling = { 1 },
142 .bit_depth = { 24 },
ef834f78 143 .planes = 1,
96c76efa 144 .buffers = 1,
ef834f78
HV
145 },
146 {
147 .name = "RGB24 (BE)",
148 .fourcc = V4L2_PIX_FMT_BGR24, /* bgr */
96c76efa
HV
149 .vdownsampling = { 1 },
150 .bit_depth = { 24 },
ef834f78 151 .planes = 1,
96c76efa 152 .buffers = 1,
ef834f78
HV
153 },
154 {
155 .name = "RGB32 (LE)",
156 .fourcc = V4L2_PIX_FMT_RGB32, /* argb */
96c76efa
HV
157 .vdownsampling = { 1 },
158 .bit_depth = { 32 },
ef834f78 159 .planes = 1,
96c76efa 160 .buffers = 1,
ef834f78
HV
161 },
162 {
163 .name = "RGB32 (BE)",
164 .fourcc = V4L2_PIX_FMT_BGR32, /* bgra */
96c76efa
HV
165 .vdownsampling = { 1 },
166 .bit_depth = { 32 },
ef834f78 167 .planes = 1,
96c76efa 168 .buffers = 1,
ef834f78
HV
169 },
170 {
171 .name = "XRGB32 (LE)",
172 .fourcc = V4L2_PIX_FMT_XRGB32, /* argb */
96c76efa
HV
173 .vdownsampling = { 1 },
174 .bit_depth = { 32 },
ef834f78 175 .planes = 1,
96c76efa 176 .buffers = 1,
ef834f78
HV
177 },
178 {
179 .name = "XRGB32 (BE)",
180 .fourcc = V4L2_PIX_FMT_XBGR32, /* bgra */
96c76efa
HV
181 .vdownsampling = { 1 },
182 .bit_depth = { 32 },
ef834f78 183 .planes = 1,
96c76efa 184 .buffers = 1,
ef834f78
HV
185 },
186 {
187 .name = "ARGB32 (LE)",
188 .fourcc = V4L2_PIX_FMT_ARGB32, /* argb */
96c76efa
HV
189 .vdownsampling = { 1 },
190 .bit_depth = { 32 },
ef834f78 191 .planes = 1,
96c76efa 192 .buffers = 1,
ef834f78
HV
193 .alpha_mask = 0x000000ff,
194 },
195 {
196 .name = "ARGB32 (BE)",
197 .fourcc = V4L2_PIX_FMT_ABGR32, /* bgra */
96c76efa
HV
198 .vdownsampling = { 1 },
199 .bit_depth = { 32 },
ef834f78 200 .planes = 1,
96c76efa 201 .buffers = 1,
ef834f78
HV
202 .alpha_mask = 0xff000000,
203 },
204 {
96c76efa 205 .name = "4:2:2, biplanar, YUV",
ef834f78 206 .fourcc = V4L2_PIX_FMT_NV16M,
96c76efa
HV
207 .vdownsampling = { 1, 1 },
208 .bit_depth = { 8, 8 },
ef834f78
HV
209 .is_yuv = true,
210 .planes = 2,
96c76efa 211 .buffers = 2,
ef834f78
HV
212 .data_offset = { PLANE0_DATA_OFFSET, 0 },
213 },
214 {
96c76efa 215 .name = "4:2:2, biplanar, YVU",
ef834f78 216 .fourcc = V4L2_PIX_FMT_NV61M,
96c76efa
HV
217 .vdownsampling = { 1, 1 },
218 .bit_depth = { 8, 8 },
ef834f78
HV
219 .is_yuv = true,
220 .planes = 2,
96c76efa 221 .buffers = 2,
ef834f78
HV
222 .data_offset = { 0, PLANE0_DATA_OFFSET },
223 },
224};
225
226/* There are 2 multiplanar formats in the list */
227#define VIVID_MPLANAR_FORMATS 2
228
1fc78bc9 229const struct vivid_fmt *vivid_get_format(struct vivid_dev *dev, u32 pixelformat)
ef834f78
HV
230{
231 const struct vivid_fmt *fmt;
232 unsigned k;
233
234 for (k = 0; k < ARRAY_SIZE(vivid_formats); k++) {
235 fmt = &vivid_formats[k];
236 if (fmt->fourcc == pixelformat)
237 if (fmt->planes == 1 || dev->multiplanar)
238 return fmt;
239 }
240
241 return NULL;
242}
243
244bool vivid_vid_can_loop(struct vivid_dev *dev)
245{
246 if (dev->src_rect.width != dev->sink_rect.width ||
247 dev->src_rect.height != dev->sink_rect.height)
248 return false;
249 if (dev->fmt_cap->fourcc != dev->fmt_out->fourcc)
250 return false;
251 if (dev->field_cap != dev->field_out)
252 return false;
ba24b442
HV
253 /*
254 * While this can be supported, it is just too much work
255 * to actually implement.
256 */
257 if (dev->field_cap == V4L2_FIELD_SEQ_TB ||
258 dev->field_cap == V4L2_FIELD_SEQ_BT)
259 return false;
ef834f78
HV
260 if (vivid_is_svid_cap(dev) && vivid_is_svid_out(dev)) {
261 if (!(dev->std_cap & V4L2_STD_525_60) !=
262 !(dev->std_out & V4L2_STD_525_60))
263 return false;
264 return true;
265 }
266 if (vivid_is_hdmi_cap(dev) && vivid_is_hdmi_out(dev))
267 return true;
268 return false;
269}
270
271void vivid_send_source_change(struct vivid_dev *dev, unsigned type)
272{
273 struct v4l2_event ev = {
274 .type = V4L2_EVENT_SOURCE_CHANGE,
275 .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
276 };
277 unsigned i;
278
279 for (i = 0; i < dev->num_inputs; i++) {
280 ev.id = i;
281 if (dev->input_type[i] == type) {
282 if (video_is_registered(&dev->vid_cap_dev) && dev->has_vid_cap)
283 v4l2_event_queue(&dev->vid_cap_dev, &ev);
284 if (video_is_registered(&dev->vbi_cap_dev) && dev->has_vbi_cap)
285 v4l2_event_queue(&dev->vbi_cap_dev, &ev);
286 }
287 }
288}
289
290/*
291 * Conversion function that converts a single-planar format to a
292 * single-plane multiplanar format.
293 */
294void fmt_sp2mp(const struct v4l2_format *sp_fmt, struct v4l2_format *mp_fmt)
295{
296 struct v4l2_pix_format_mplane *mp = &mp_fmt->fmt.pix_mp;
297 struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0];
298 const struct v4l2_pix_format *pix = &sp_fmt->fmt.pix;
299 bool is_out = sp_fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT;
300
301 memset(mp->reserved, 0, sizeof(mp->reserved));
302 mp_fmt->type = is_out ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE :
303 V4L2_CAP_VIDEO_CAPTURE_MPLANE;
304 mp->width = pix->width;
305 mp->height = pix->height;
306 mp->pixelformat = pix->pixelformat;
307 mp->field = pix->field;
308 mp->colorspace = pix->colorspace;
3e8a78d1
HV
309 mp->ycbcr_enc = pix->ycbcr_enc;
310 mp->quantization = pix->quantization;
ef834f78
HV
311 mp->num_planes = 1;
312 mp->flags = pix->flags;
313 ppix->sizeimage = pix->sizeimage;
314 ppix->bytesperline = pix->bytesperline;
315 memset(ppix->reserved, 0, sizeof(ppix->reserved));
316}
317
318int fmt_sp2mp_func(struct file *file, void *priv,
319 struct v4l2_format *f, fmtfunc func)
320{
321 struct v4l2_format fmt;
322 struct v4l2_pix_format_mplane *mp = &fmt.fmt.pix_mp;
323 struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0];
324 struct v4l2_pix_format *pix = &f->fmt.pix;
325 int ret;
326
327 /* Converts to a mplane format */
328 fmt_sp2mp(f, &fmt);
329 /* Passes it to the generic mplane format function */
330 ret = func(file, priv, &fmt);
331 /* Copies back the mplane data to the single plane format */
332 pix->width = mp->width;
333 pix->height = mp->height;
334 pix->pixelformat = mp->pixelformat;
335 pix->field = mp->field;
336 pix->colorspace = mp->colorspace;
3e8a78d1
HV
337 pix->ycbcr_enc = mp->ycbcr_enc;
338 pix->quantization = mp->quantization;
ef834f78
HV
339 pix->sizeimage = ppix->sizeimage;
340 pix->bytesperline = ppix->bytesperline;
341 pix->flags = mp->flags;
342 return ret;
343}
344
345/* v4l2_rect helper function: copy the width/height values */
346void rect_set_size_to(struct v4l2_rect *r, const struct v4l2_rect *size)
347{
348 r->width = size->width;
349 r->height = size->height;
350}
351
352/* v4l2_rect helper function: width and height of r should be >= min_size */
353void rect_set_min_size(struct v4l2_rect *r, const struct v4l2_rect *min_size)
354{
355 if (r->width < min_size->width)
356 r->width = min_size->width;
357 if (r->height < min_size->height)
358 r->height = min_size->height;
359}
360
361/* v4l2_rect helper function: width and height of r should be <= max_size */
362void rect_set_max_size(struct v4l2_rect *r, const struct v4l2_rect *max_size)
363{
364 if (r->width > max_size->width)
365 r->width = max_size->width;
366 if (r->height > max_size->height)
367 r->height = max_size->height;
368}
369
370/* v4l2_rect helper function: r should be inside boundary */
371void rect_map_inside(struct v4l2_rect *r, const struct v4l2_rect *boundary)
372{
373 rect_set_max_size(r, boundary);
374 if (r->left < boundary->left)
375 r->left = boundary->left;
376 if (r->top < boundary->top)
377 r->top = boundary->top;
378 if (r->left + r->width > boundary->width)
379 r->left = boundary->width - r->width;
380 if (r->top + r->height > boundary->height)
381 r->top = boundary->height - r->height;
382}
383
384/* v4l2_rect helper function: return true if r1 has the same size as r2 */
385bool rect_same_size(const struct v4l2_rect *r1, const struct v4l2_rect *r2)
386{
387 return r1->width == r2->width && r1->height == r2->height;
388}
389
390/* v4l2_rect helper function: calculate the intersection of two rects */
391struct v4l2_rect rect_intersect(const struct v4l2_rect *a, const struct v4l2_rect *b)
392{
393 struct v4l2_rect r;
394 int right, bottom;
395
396 r.top = max(a->top, b->top);
397 r.left = max(a->left, b->left);
398 bottom = min(a->top + a->height, b->top + b->height);
399 right = min(a->left + a->width, b->left + b->width);
400 r.height = max(0, bottom - r.top);
401 r.width = max(0, right - r.left);
402 return r;
403}
404
405/*
406 * v4l2_rect helper function: scale rect r by to->width / from->width and
407 * to->height / from->height.
408 */
409void rect_scale(struct v4l2_rect *r, const struct v4l2_rect *from,
410 const struct v4l2_rect *to)
411{
412 if (from->width == 0 || from->height == 0) {
413 r->left = r->top = r->width = r->height = 0;
414 return;
415 }
416 r->left = (((r->left - from->left) * to->width) / from->width) & ~1;
417 r->width = ((r->width * to->width) / from->width) & ~1;
418 r->top = ((r->top - from->top) * to->height) / from->height;
419 r->height = (r->height * to->height) / from->height;
420}
421
422bool rect_overlap(const struct v4l2_rect *r1, const struct v4l2_rect *r2)
423{
424 /*
425 * IF the left side of r1 is to the right of the right side of r2 OR
426 * the left side of r2 is to the right of the right side of r1 THEN
427 * they do not overlap.
428 */
429 if (r1->left >= r2->left + r2->width ||
430 r2->left >= r1->left + r1->width)
431 return false;
432 /*
433 * IF the top side of r1 is below the bottom of r2 OR
434 * the top side of r2 is below the bottom of r1 THEN
435 * they do not overlap.
436 */
437 if (r1->top >= r2->top + r2->height ||
438 r2->top >= r1->top + r1->height)
439 return false;
440 return true;
441}
442int vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r)
443{
444 unsigned w = r->width;
445 unsigned h = r->height;
446
447 if (!(flags & V4L2_SEL_FLAG_LE)) {
448 w++;
449 h++;
450 if (w < 2)
451 w = 2;
452 if (h < 2)
453 h = 2;
454 }
455 if (!(flags & V4L2_SEL_FLAG_GE)) {
456 if (w > MAX_WIDTH)
457 w = MAX_WIDTH;
458 if (h > MAX_HEIGHT)
459 h = MAX_HEIGHT;
460 }
461 w = w & ~1;
462 h = h & ~1;
463 if (w < 2 || h < 2)
464 return -ERANGE;
465 if (w > MAX_WIDTH || h > MAX_HEIGHT)
466 return -ERANGE;
467 if (r->top < 0)
468 r->top = 0;
469 if (r->left < 0)
470 r->left = 0;
471 r->left &= ~1;
472 r->top &= ~1;
473 if (r->left + w > MAX_WIDTH)
474 r->left = MAX_WIDTH - w;
475 if (r->top + h > MAX_HEIGHT)
476 r->top = MAX_HEIGHT - h;
477 if ((flags & (V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE)) ==
478 (V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE) &&
479 (r->width != w || r->height != h))
480 return -ERANGE;
481 r->width = w;
482 r->height = h;
483 return 0;
484}
485
486int vivid_enum_fmt_vid(struct file *file, void *priv,
487 struct v4l2_fmtdesc *f)
488{
489 struct vivid_dev *dev = video_drvdata(file);
490 const struct vivid_fmt *fmt;
491
492 if (f->index >= ARRAY_SIZE(vivid_formats) -
493 (dev->multiplanar ? 0 : VIVID_MPLANAR_FORMATS))
494 return -EINVAL;
495
496 fmt = &vivid_formats[f->index];
497
498 strlcpy(f->description, fmt->name, sizeof(f->description));
499 f->pixelformat = fmt->fourcc;
500 return 0;
501}
502
503int vidioc_enum_fmt_vid_mplane(struct file *file, void *priv,
504 struct v4l2_fmtdesc *f)
505{
506 struct vivid_dev *dev = video_drvdata(file);
507
508 if (!dev->multiplanar)
509 return -ENOTTY;
510 return vivid_enum_fmt_vid(file, priv, f);
511}
512
513int vidioc_enum_fmt_vid(struct file *file, void *priv,
514 struct v4l2_fmtdesc *f)
515{
516 struct vivid_dev *dev = video_drvdata(file);
517
518 if (dev->multiplanar)
519 return -ENOTTY;
520 return vivid_enum_fmt_vid(file, priv, f);
521}
522
523int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
524{
525 struct vivid_dev *dev = video_drvdata(file);
526 struct video_device *vdev = video_devdata(file);
527
528 if (vdev->vfl_dir == VFL_DIR_RX) {
529 if (!vivid_is_sdtv_cap(dev))
530 return -ENODATA;
531 *id = dev->std_cap;
532 } else {
533 if (!vivid_is_svid_out(dev))
534 return -ENODATA;
535 *id = dev->std_out;
536 }
537 return 0;
538}
539
540int vidioc_g_dv_timings(struct file *file, void *_fh,
541 struct v4l2_dv_timings *timings)
542{
543 struct vivid_dev *dev = video_drvdata(file);
544 struct video_device *vdev = video_devdata(file);
545
546 if (vdev->vfl_dir == VFL_DIR_RX) {
547 if (!vivid_is_hdmi_cap(dev))
548 return -ENODATA;
549 *timings = dev->dv_timings_cap;
550 } else {
551 if (!vivid_is_hdmi_out(dev))
552 return -ENODATA;
553 *timings = dev->dv_timings_out;
554 }
555 return 0;
556}
557
558int vidioc_enum_dv_timings(struct file *file, void *_fh,
559 struct v4l2_enum_dv_timings *timings)
560{
561 struct vivid_dev *dev = video_drvdata(file);
562 struct video_device *vdev = video_devdata(file);
563
564 if (vdev->vfl_dir == VFL_DIR_RX) {
565 if (!vivid_is_hdmi_cap(dev))
566 return -ENODATA;
567 } else {
568 if (!vivid_is_hdmi_out(dev))
569 return -ENODATA;
570 }
571 return v4l2_enum_dv_timings_cap(timings, &vivid_dv_timings_cap,
572 NULL, NULL);
573}
574
575int vidioc_dv_timings_cap(struct file *file, void *_fh,
576 struct v4l2_dv_timings_cap *cap)
577{
578 struct vivid_dev *dev = video_drvdata(file);
579 struct video_device *vdev = video_devdata(file);
580
581 if (vdev->vfl_dir == VFL_DIR_RX) {
582 if (!vivid_is_hdmi_cap(dev))
583 return -ENODATA;
584 } else {
585 if (!vivid_is_hdmi_out(dev))
586 return -ENODATA;
587 }
588 *cap = vivid_dv_timings_cap;
589 return 0;
590}
591
592int vidioc_g_edid(struct file *file, void *_fh,
593 struct v4l2_edid *edid)
594{
595 struct vivid_dev *dev = video_drvdata(file);
596 struct video_device *vdev = video_devdata(file);
597
598 memset(edid->reserved, 0, sizeof(edid->reserved));
599 if (vdev->vfl_dir == VFL_DIR_RX) {
600 if (edid->pad >= dev->num_inputs)
601 return -EINVAL;
602 if (dev->input_type[edid->pad] != HDMI)
603 return -EINVAL;
604 } else {
605 if (edid->pad >= dev->num_outputs)
606 return -EINVAL;
607 if (dev->output_type[edid->pad] != HDMI)
608 return -EINVAL;
609 }
610 if (edid->start_block == 0 && edid->blocks == 0) {
611 edid->blocks = dev->edid_blocks;
612 return 0;
613 }
614 if (dev->edid_blocks == 0)
615 return -ENODATA;
616 if (edid->start_block >= dev->edid_blocks)
617 return -EINVAL;
618 if (edid->start_block + edid->blocks > dev->edid_blocks)
619 edid->blocks = dev->edid_blocks - edid->start_block;
620 memcpy(edid->edid, dev->edid, edid->blocks * 128);
621 return 0;
622}
This page took 0.078576 seconds and 5 git commands to generate.