aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-07-29 07:40:55 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2013-08-18 07:15:46 -0400
commitb18787ed1ce32eb0c2ce2323220abd4ed93c4b97 (patch)
tree932f4aca5286fa7681add52b0be6151e2d5b6edf /drivers/media/v4l2-core
parent299878fa3c373dbf74edf5872c79ef4c65b80a04 (diff)
[media] v4l2-dv-timings: add new helper module
This module makes it easy to filter valid timings from the full list of CEA and DMT timings based on the timings capabilities. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/v4l2-core')
-rw-r--r--drivers/media/v4l2-core/Makefile1
-rw-r--r--drivers/media/v4l2-core/v4l2-dv-timings.c192
2 files changed, 193 insertions, 0 deletions
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 4c33b8d6520c..1a85eee581f8 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -17,6 +17,7 @@ endif
17obj-$(CONFIG_VIDEO_V4L2) += videodev.o 17obj-$(CONFIG_VIDEO_V4L2) += videodev.o
18obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o 18obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o
19obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o 19obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
20obj-$(CONFIG_VIDEO_V4L2) += v4l2-dv-timings.o
20 21
21obj-$(CONFIG_VIDEO_TUNER) += tuner.o 22obj-$(CONFIG_VIDEO_TUNER) += tuner.o
22 23
diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c
new file mode 100644
index 000000000000..58279467a7a5
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -0,0 +1,192 @@
1/*
2 * v4l2-dv-timings - dv-timings helper functions
3 *
4 * Copyright 2013 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
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/kernel.h>
24#include <linux/errno.h>
25#include <linux/videodev2.h>
26#include <linux/v4l2-dv-timings.h>
27#include <media/v4l2-common.h>
28#include <media/v4l2-dv-timings.h>
29
30static const struct v4l2_dv_timings timings[] = {
31 V4L2_DV_BT_CEA_640X480P59_94,
32 V4L2_DV_BT_CEA_720X480I59_94,
33 V4L2_DV_BT_CEA_720X480P59_94,
34 V4L2_DV_BT_CEA_720X576I50,
35 V4L2_DV_BT_CEA_720X576P50,
36 V4L2_DV_BT_CEA_1280X720P24,
37 V4L2_DV_BT_CEA_1280X720P25,
38 V4L2_DV_BT_CEA_1280X720P30,
39 V4L2_DV_BT_CEA_1280X720P50,
40 V4L2_DV_BT_CEA_1280X720P60,
41 V4L2_DV_BT_CEA_1920X1080P24,
42 V4L2_DV_BT_CEA_1920X1080P25,
43 V4L2_DV_BT_CEA_1920X1080P30,
44 V4L2_DV_BT_CEA_1920X1080I50,
45 V4L2_DV_BT_CEA_1920X1080P50,
46 V4L2_DV_BT_CEA_1920X1080I60,
47 V4L2_DV_BT_CEA_1920X1080P60,
48 V4L2_DV_BT_DMT_640X350P85,
49 V4L2_DV_BT_DMT_640X400P85,
50 V4L2_DV_BT_DMT_720X400P85,
51 V4L2_DV_BT_DMT_640X480P72,
52 V4L2_DV_BT_DMT_640X480P75,
53 V4L2_DV_BT_DMT_640X480P85,
54 V4L2_DV_BT_DMT_800X600P56,
55 V4L2_DV_BT_DMT_800X600P60,
56 V4L2_DV_BT_DMT_800X600P72,
57 V4L2_DV_BT_DMT_800X600P75,
58 V4L2_DV_BT_DMT_800X600P85,
59 V4L2_DV_BT_DMT_800X600P120_RB,
60 V4L2_DV_BT_DMT_848X480P60,
61 V4L2_DV_BT_DMT_1024X768I43,
62 V4L2_DV_BT_DMT_1024X768P60,
63 V4L2_DV_BT_DMT_1024X768P70,
64 V4L2_DV_BT_DMT_1024X768P75,
65 V4L2_DV_BT_DMT_1024X768P85,
66 V4L2_DV_BT_DMT_1024X768P120_RB,
67 V4L2_DV_BT_DMT_1152X864P75,
68 V4L2_DV_BT_DMT_1280X768P60_RB,
69 V4L2_DV_BT_DMT_1280X768P60,
70 V4L2_DV_BT_DMT_1280X768P75,
71 V4L2_DV_BT_DMT_1280X768P85,
72 V4L2_DV_BT_DMT_1280X768P120_RB,
73 V4L2_DV_BT_DMT_1280X800P60_RB,
74 V4L2_DV_BT_DMT_1280X800P60,
75 V4L2_DV_BT_DMT_1280X800P75,
76 V4L2_DV_BT_DMT_1280X800P85,
77 V4L2_DV_BT_DMT_1280X800P120_RB,
78 V4L2_DV_BT_DMT_1280X960P60,
79 V4L2_DV_BT_DMT_1280X960P85,
80 V4L2_DV_BT_DMT_1280X960P120_RB,
81 V4L2_DV_BT_DMT_1280X1024P60,
82 V4L2_DV_BT_DMT_1280X1024P75,
83 V4L2_DV_BT_DMT_1280X1024P85,
84 V4L2_DV_BT_DMT_1280X1024P120_RB,
85 V4L2_DV_BT_DMT_1360X768P60,
86 V4L2_DV_BT_DMT_1360X768P120_RB,
87 V4L2_DV_BT_DMT_1366X768P60,
88 V4L2_DV_BT_DMT_1366X768P60_RB,
89 V4L2_DV_BT_DMT_1400X1050P60_RB,
90 V4L2_DV_BT_DMT_1400X1050P60,
91 V4L2_DV_BT_DMT_1400X1050P75,
92 V4L2_DV_BT_DMT_1400X1050P85,
93 V4L2_DV_BT_DMT_1400X1050P120_RB,
94 V4L2_DV_BT_DMT_1440X900P60_RB,
95 V4L2_DV_BT_DMT_1440X900P60,
96 V4L2_DV_BT_DMT_1440X900P75,
97 V4L2_DV_BT_DMT_1440X900P85,
98 V4L2_DV_BT_DMT_1440X900P120_RB,
99 V4L2_DV_BT_DMT_1600X900P60_RB,
100 V4L2_DV_BT_DMT_1600X1200P60,
101 V4L2_DV_BT_DMT_1600X1200P65,
102 V4L2_DV_BT_DMT_1600X1200P70,
103 V4L2_DV_BT_DMT_1600X1200P75,
104 V4L2_DV_BT_DMT_1600X1200P85,
105 V4L2_DV_BT_DMT_1600X1200P120_RB,
106 V4L2_DV_BT_DMT_1680X1050P60_RB,
107 V4L2_DV_BT_DMT_1680X1050P60,
108 V4L2_DV_BT_DMT_1680X1050P75,
109 V4L2_DV_BT_DMT_1680X1050P85,
110 V4L2_DV_BT_DMT_1680X1050P120_RB,
111 V4L2_DV_BT_DMT_1792X1344P60,
112 V4L2_DV_BT_DMT_1792X1344P75,
113 V4L2_DV_BT_DMT_1792X1344P120_RB,
114 V4L2_DV_BT_DMT_1856X1392P60,
115 V4L2_DV_BT_DMT_1856X1392P75,
116 V4L2_DV_BT_DMT_1856X1392P120_RB,
117 V4L2_DV_BT_DMT_1920X1200P60_RB,
118 V4L2_DV_BT_DMT_1920X1200P60,
119 V4L2_DV_BT_DMT_1920X1200P75,
120 V4L2_DV_BT_DMT_1920X1200P85,
121 V4L2_DV_BT_DMT_1920X1200P120_RB,
122 V4L2_DV_BT_DMT_1920X1440P60,
123 V4L2_DV_BT_DMT_1920X1440P75,
124 V4L2_DV_BT_DMT_1920X1440P120_RB,
125 V4L2_DV_BT_DMT_2048X1152P60_RB,
126 V4L2_DV_BT_DMT_2560X1600P60_RB,
127 V4L2_DV_BT_DMT_2560X1600P60,
128 V4L2_DV_BT_DMT_2560X1600P75,
129 V4L2_DV_BT_DMT_2560X1600P85,
130 V4L2_DV_BT_DMT_2560X1600P120_RB,
131};
132
133bool v4l2_dv_valid_timings(const struct v4l2_dv_timings *t,
134 const struct v4l2_dv_timings_cap *dvcap)
135{
136 const struct v4l2_bt_timings *bt = &t->bt;
137 const struct v4l2_bt_timings_cap *cap = &dvcap->bt;
138 u32 caps = cap->capabilities;
139
140 if (t->type != V4L2_DV_BT_656_1120)
141 return false;
142 if (t->type != dvcap->type ||
143 bt->height < cap->min_height ||
144 bt->height > cap->max_height ||
145 bt->width < cap->min_width ||
146 bt->width > cap->max_width ||
147 bt->pixelclock < cap->min_pixelclock ||
148 bt->pixelclock > cap->max_pixelclock ||
149 (cap->standards && !(bt->standards & cap->standards)) ||
150 (bt->interlaced && !(caps & V4L2_DV_BT_CAP_INTERLACED)) ||
151 (!bt->interlaced && !(caps & V4L2_DV_BT_CAP_PROGRESSIVE)))
152 return false;
153 return true;
154}
155EXPORT_SYMBOL_GPL(v4l2_dv_valid_timings);
156
157int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
158 const struct v4l2_dv_timings_cap *cap)
159{
160 u32 i, idx;
161
162 memset(t->reserved, 0, sizeof(t->reserved));
163 for (i = idx = 0; i < ARRAY_SIZE(timings); i++) {
164 if (v4l2_dv_valid_timings(timings + i, cap) &&
165 idx++ == t->index) {
166 t->timings = timings[i];
167 return 0;
168 }
169 }
170 return -EINVAL;
171}
172EXPORT_SYMBOL_GPL(v4l2_enum_dv_timings_cap);
173
174bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
175 const struct v4l2_dv_timings_cap *cap,
176 unsigned pclock_delta)
177{
178 int i;
179
180 if (!v4l2_dv_valid_timings(t, cap))
181 return false;
182
183 for (i = 0; i < ARRAY_SIZE(timings); i++) {
184 if (v4l2_dv_valid_timings(timings + i, cap) &&
185 v4l_match_dv_timings(t, timings + i, pclock_delta)) {
186 *t = timings[i];
187 return true;
188 }
189 }
190 return false;
191}
192EXPORT_SYMBOL_GPL(v4l2_find_dv_timings_cap);