diff options
Diffstat (limited to 'drivers/media/video/bttv-vbi.c')
-rw-r--r-- | drivers/media/video/bttv-vbi.c | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/drivers/media/video/bttv-vbi.c b/drivers/media/video/bttv-vbi.c index f4f58c60f152..72afdd64b882 100644 --- a/drivers/media/video/bttv-vbi.c +++ b/drivers/media/video/bttv-vbi.c | |||
@@ -31,6 +31,12 @@ | |||
31 | #include <asm/io.h> | 31 | #include <asm/io.h> |
32 | #include "bttvp.h" | 32 | #include "bttvp.h" |
33 | 33 | ||
34 | /* Offset from line sync pulse leading edge (0H) in 1 / sampling_rate: | ||
35 | bt8x8 /HRESET pulse starts at 0H and has length 64 / fCLKx1 (E|O_VTC | ||
36 | HSFMT = 0). VBI_HDELAY (always 0) is an offset from the trailing edge | ||
37 | of /HRESET in 1 / fCLKx1, and the sampling_rate tvnorm->Fsc is fCLKx2. */ | ||
38 | #define VBI_OFFSET ((64 + 0) * 2) | ||
39 | |||
34 | #define VBI_DEFLINES 16 | 40 | #define VBI_DEFLINES 16 |
35 | #define VBI_MAXLINES 32 | 41 | #define VBI_MAXLINES 32 |
36 | 42 | ||
@@ -163,40 +169,30 @@ void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines) | |||
163 | void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f) | 169 | void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f) |
164 | { | 170 | { |
165 | const struct bttv_tvnorm *tvnorm; | 171 | const struct bttv_tvnorm *tvnorm; |
166 | u32 start0,start1; | 172 | s64 count0,count1,count; |
167 | s32 count0,count1,count; | ||
168 | 173 | ||
169 | tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; | 174 | tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; |
170 | f->type = V4L2_BUF_TYPE_VBI_CAPTURE; | 175 | f->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
171 | f->fmt.vbi.sampling_rate = tvnorm->Fsc; | 176 | f->fmt.vbi.sampling_rate = tvnorm->Fsc; |
172 | f->fmt.vbi.samples_per_line = 2048; | 177 | f->fmt.vbi.samples_per_line = 2048; |
173 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; | 178 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
174 | f->fmt.vbi.offset = 244; | 179 | f->fmt.vbi.offset = VBI_OFFSET; |
175 | f->fmt.vbi.flags = 0; | 180 | f->fmt.vbi.flags = 0; |
176 | switch (fh->btv->tvnorm) { | ||
177 | case 1: /* NTSC */ | ||
178 | start0 = 10; | ||
179 | start1 = 273; | ||
180 | break; | ||
181 | case 0: /* PAL */ | ||
182 | case 2: /* SECAM */ | ||
183 | default: | ||
184 | start0 = 7; | ||
185 | start1 = 320; | ||
186 | } | ||
187 | 181 | ||
188 | count0 = (f->fmt.vbi.start[0] + f->fmt.vbi.count[0]) - start0; | 182 | /* s64 to prevent overflow. */ |
189 | count1 = (f->fmt.vbi.start[1] + f->fmt.vbi.count[1]) - start1; | 183 | count0 = (s64) f->fmt.vbi.start[0] + f->fmt.vbi.count[0] |
190 | count = max(count0,count1); | 184 | - tvnorm->vbistart[0]; |
191 | if (count > VBI_MAXLINES) | 185 | count1 = (s64) f->fmt.vbi.start[1] + f->fmt.vbi.count[1] |
192 | count = VBI_MAXLINES; | 186 | - tvnorm->vbistart[1]; |
193 | if (count < 1) | 187 | count = clamp (max (count0, count1), 1LL, (s64) VBI_MAXLINES); |
194 | count = 1; | ||
195 | 188 | ||
196 | f->fmt.vbi.start[0] = start0; | 189 | f->fmt.vbi.start[0] = tvnorm->vbistart[0]; |
197 | f->fmt.vbi.start[1] = start1; | 190 | f->fmt.vbi.start[1] = tvnorm->vbistart[1]; |
198 | f->fmt.vbi.count[0] = count; | 191 | f->fmt.vbi.count[0] = count; |
199 | f->fmt.vbi.count[1] = count; | 192 | f->fmt.vbi.count[1] = count; |
193 | |||
194 | f->fmt.vbi.reserved[0] = 0; | ||
195 | f->fmt.vbi.reserved[1] = 0; | ||
200 | } | 196 | } |
201 | 197 | ||
202 | void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f) | 198 | void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f) |
@@ -209,21 +205,12 @@ void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f) | |||
209 | f->fmt.vbi.sampling_rate = tvnorm->Fsc; | 205 | f->fmt.vbi.sampling_rate = tvnorm->Fsc; |
210 | f->fmt.vbi.samples_per_line = 2048; | 206 | f->fmt.vbi.samples_per_line = 2048; |
211 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; | 207 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
212 | f->fmt.vbi.offset = 244; | 208 | f->fmt.vbi.offset = VBI_OFFSET; |
209 | f->fmt.vbi.start[0] = tvnorm->vbistart[0]; | ||
210 | f->fmt.vbi.start[1] = tvnorm->vbistart[1]; | ||
213 | f->fmt.vbi.count[0] = fh->lines; | 211 | f->fmt.vbi.count[0] = fh->lines; |
214 | f->fmt.vbi.count[1] = fh->lines; | 212 | f->fmt.vbi.count[1] = fh->lines; |
215 | f->fmt.vbi.flags = 0; | 213 | f->fmt.vbi.flags = 0; |
216 | switch (fh->btv->tvnorm) { | ||
217 | case 1: /* NTSC */ | ||
218 | f->fmt.vbi.start[0] = 10; | ||
219 | f->fmt.vbi.start[1] = 273; | ||
220 | break; | ||
221 | case 0: /* PAL */ | ||
222 | case 2: /* SECAM */ | ||
223 | default: | ||
224 | f->fmt.vbi.start[0] = 7; | ||
225 | f->fmt.vbi.start[1] = 319; | ||
226 | } | ||
227 | } | 214 | } |
228 | 215 | ||
229 | /* ----------------------------------------------------------------------- */ | 216 | /* ----------------------------------------------------------------------- */ |