aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/bt819.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-02-18 15:26:06 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:42:57 -0400
commit107063c6156a0cbf055e771baafc28a3e3c0fb9b (patch)
tree813a2dc2c1426521167f2f289d7a106aaf2f24ec /drivers/media/video/bt819.c
parent84c1b09495ea366276726b0df2dcd7898cda9d0f (diff)
V4L/DVB (10714): zoran et al: convert zoran i2c modules to V4L2.
The zoran i2c modules were still using V4L1 internally. Replace this with V4L2. Also deleted saa7111.c and saa7114.c, we use saa7115.c instead. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> [mchehab@redhat.com: fix v4l2_ctrl_query_fill_std merge conflict] Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/bt819.c')
-rw-r--r--drivers/media/video/bt819.c271
1 files changed, 142 insertions, 129 deletions
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index a07b7b88e5b8..b8109a1b50ce 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -54,7 +54,7 @@ struct bt819 {
54 unsigned char reg[32]; 54 unsigned char reg[32];
55 55
56 int initialized; 56 int initialized;
57 int norm; 57 v4l2_std_id norm;
58 int input; 58 int input;
59 int enable; 59 int enable;
60 int bright; 60 int bright;
@@ -178,7 +178,7 @@ static int bt819_init(struct i2c_client *client)
178 0x1a, 0x80, /* 0x1a ADC Interface */ 178 0x1a, 0x80, /* 0x1a ADC Interface */
179 }; 179 };
180 180
181 struct timing *timing = &timing_data[decoder->norm]; 181 struct timing *timing = &timing_data[(decoder->norm & V4L2_STD_525_60) ? 1 : 0];
182 182
183 init[0x03 * 2 - 1] = 183 init[0x03 * 2 - 1] =
184 (((timing->vdelay >> 8) & 0x03) << 6) | 184 (((timing->vdelay >> 8) & 0x03) << 6) |
@@ -192,7 +192,7 @@ static int bt819_init(struct i2c_client *client)
192 init[0x08 * 2 - 1] = timing->hscale >> 8; 192 init[0x08 * 2 - 1] = timing->hscale >> 8;
193 init[0x09 * 2 - 1] = timing->hscale & 0xff; 193 init[0x09 * 2 - 1] = timing->hscale & 0xff;
194 /* 0x15 in array is address 0x19 */ 194 /* 0x15 in array is address 0x19 */
195 init[0x15 * 2 - 1] = (decoder->norm == 0) ? 115 : 93; /* Chroma burst delay */ 195 init[0x15 * 2 - 1] = (decoder->norm & V4L2_STD_625_50) ? 115 : 93; /* Chroma burst delay */
196 /* reset */ 196 /* reset */
197 bt819_write(client, 0x1f, 0x00); 197 bt819_write(client, 0x1f, 0x00);
198 mdelay(1); 198 mdelay(1);
@@ -215,121 +215,93 @@ static int bt819_command(struct i2c_client *client, unsigned cmd, void *arg)
215 } 215 }
216 216
217 switch (cmd) { 217 switch (cmd) {
218 case 0: 218 case VIDIOC_INT_INIT:
219 /* This is just for testing!!! */ 219 /* This is just for testing!!! */
220 bt819_init(client); 220 bt819_init(client);
221 break; 221 break;
222 222
223 case DECODER_GET_CAPABILITIES: 223 case VIDIOC_QUERYSTD:
224 { 224 case VIDIOC_INT_G_INPUT_STATUS: {
225 struct video_decoder_capability *cap = arg;
226
227 cap->flags = VIDEO_DECODER_PAL |
228 VIDEO_DECODER_NTSC |
229 VIDEO_DECODER_AUTO |
230 VIDEO_DECODER_CCIR;
231 cap->inputs = 8;
232 cap->outputs = 1;
233 break;
234 }
235
236 case DECODER_GET_STATUS:
237 {
238 int *iarg = arg; 225 int *iarg = arg;
226 v4l2_std_id *istd = arg;
239 int status; 227 int status;
240 int res; 228 int res = V4L2_IN_ST_NO_SIGNAL;
229 v4l2_std_id std;
241 230
242 status = bt819_read(client, 0x00); 231 status = bt819_read(client, 0x00);
243 res = 0;
244 if ((status & 0x80)) 232 if ((status & 0x80))
245 res |= DECODER_STATUS_GOOD; 233 res = 0;
246 234
247 switch (decoder->norm) { 235 if ((status & 0x10))
248 case VIDEO_MODE_NTSC: 236 std = V4L2_STD_PAL;
249 res |= DECODER_STATUS_NTSC; 237 else
250 break; 238 std = V4L2_STD_NTSC;
251 case VIDEO_MODE_PAL: 239 if (cmd == VIDIOC_QUERYSTD)
252 res |= DECODER_STATUS_PAL; 240 *istd = std;
253 break; 241 else
254 default: 242 *iarg = res;
255 case VIDEO_MODE_AUTO:
256 if ((status & 0x10))
257 res |= DECODER_STATUS_PAL;
258 else
259 res |= DECODER_STATUS_NTSC;
260 break;
261 }
262 res |= DECODER_STATUS_COLOR;
263 *iarg = res;
264 243
265 v4l_dbg(1, debug, client, "get status %x\n", *iarg); 244 v4l_dbg(1, debug, client, "get status %x\n", *iarg);
266 break; 245 break;
267 } 246 }
268 247
269 case DECODER_SET_NORM: 248 case VIDIOC_S_STD:
270 { 249 {
271 int *iarg = arg; 250 v4l2_std_id *iarg = arg;
272 struct timing *timing = NULL; 251 struct timing *timing = NULL;
273 252
274 v4l_dbg(1, debug, client, "set norm %x\n", *iarg); 253 v4l_dbg(1, debug, client, "set norm %llx\n", *iarg);
275 254
276 switch (*iarg) { 255 if (*iarg & V4L2_STD_NTSC) {
277 case VIDEO_MODE_NTSC:
278 bt819_setbit(client, 0x01, 0, 1); 256 bt819_setbit(client, 0x01, 0, 1);
279 bt819_setbit(client, 0x01, 1, 0); 257 bt819_setbit(client, 0x01, 1, 0);
280 bt819_setbit(client, 0x01, 5, 0); 258 bt819_setbit(client, 0x01, 5, 0);
281 bt819_write(client, 0x18, 0x68); 259 bt819_write(client, 0x18, 0x68);
282 bt819_write(client, 0x19, 0x5d); 260 bt819_write(client, 0x19, 0x5d);
283 /* bt819_setbit(client, 0x1a, 5, 1); */ 261 /* bt819_setbit(client, 0x1a, 5, 1); */
284 timing = &timing_data[VIDEO_MODE_NTSC]; 262 timing = &timing_data[1];
285 break; 263 } else if (*iarg & V4L2_STD_PAL) {
286 case VIDEO_MODE_PAL:
287 bt819_setbit(client, 0x01, 0, 1); 264 bt819_setbit(client, 0x01, 0, 1);
288 bt819_setbit(client, 0x01, 1, 1); 265 bt819_setbit(client, 0x01, 1, 1);
289 bt819_setbit(client, 0x01, 5, 1); 266 bt819_setbit(client, 0x01, 5, 1);
290 bt819_write(client, 0x18, 0x7f); 267 bt819_write(client, 0x18, 0x7f);
291 bt819_write(client, 0x19, 0x72); 268 bt819_write(client, 0x19, 0x72);
292 /* bt819_setbit(client, 0x1a, 5, 0); */ 269 /* bt819_setbit(client, 0x1a, 5, 0); */
293 timing = &timing_data[VIDEO_MODE_PAL]; 270 timing = &timing_data[0];
294 break; 271 } else {
295 case VIDEO_MODE_AUTO: 272 v4l_dbg(1, debug, client, "unsupported norm %llx\n", *iarg);
296 bt819_setbit(client, 0x01, 0, 0);
297 bt819_setbit(client, 0x01, 1, 0);
298 break;
299 default:
300 v4l_dbg(1, debug, client, "unsupported norm %x\n", *iarg);
301 return -EINVAL; 273 return -EINVAL;
302 } 274 }
303 275/* case VIDEO_MODE_AUTO:
304 if (timing) { 276 bt819_setbit(client, 0x01, 0, 0);
305 bt819_write(client, 0x03, 277 bt819_setbit(client, 0x01, 1, 0);*/
306 (((timing->vdelay >> 8) & 0x03) << 6) | 278
307 (((timing->vactive >> 8) & 0x03) << 4) | 279 bt819_write(client, 0x03,
308 (((timing->hdelay >> 8) & 0x03) << 2) | 280 (((timing->vdelay >> 8) & 0x03) << 6) |
309 ((timing->hactive >> 8) & 0x03) ); 281 (((timing->vactive >> 8) & 0x03) << 4) |
310 bt819_write(client, 0x04, timing->vdelay & 0xff); 282 (((timing->hdelay >> 8) & 0x03) << 2) |
311 bt819_write(client, 0x05, timing->vactive & 0xff); 283 ((timing->hactive >> 8) & 0x03));
312 bt819_write(client, 0x06, timing->hdelay & 0xff); 284 bt819_write(client, 0x04, timing->vdelay & 0xff);
313 bt819_write(client, 0x07, timing->hactive & 0xff); 285 bt819_write(client, 0x05, timing->vactive & 0xff);
314 bt819_write(client, 0x08, (timing->hscale >> 8) & 0xff); 286 bt819_write(client, 0x06, timing->hdelay & 0xff);
315 bt819_write(client, 0x09, timing->hscale & 0xff); 287 bt819_write(client, 0x07, timing->hactive & 0xff);
316 } 288 bt819_write(client, 0x08, (timing->hscale >> 8) & 0xff);
317 289 bt819_write(client, 0x09, timing->hscale & 0xff);
318 decoder->norm = *iarg; 290 decoder->norm = *iarg;
319 break; 291 break;
320 } 292 }
321 293
322 case DECODER_SET_INPUT: 294 case VIDIOC_INT_S_VIDEO_ROUTING:
323 { 295 {
324 int *iarg = arg; 296 struct v4l2_routing *route = arg;
325 297
326 v4l_dbg(1, debug, client, "set input %x\n", *iarg); 298 v4l_dbg(1, debug, client, "set input %x\n", route->input);
327 299
328 if (*iarg < 0 || *iarg > 7) 300 if (route->input < 0 || route->input > 7)
329 return -EINVAL; 301 return -EINVAL;
330 302
331 if (decoder->input != *iarg) { 303 if (decoder->input != route->input) {
332 decoder->input = *iarg; 304 decoder->input = route->input;
333 /* select mode */ 305 /* select mode */
334 if (decoder->input == 0) { 306 if (decoder->input == 0) {
335 bt819_setbit(client, 0x0b, 6, 0); 307 bt819_setbit(client, 0x0b, 6, 0);
@@ -342,75 +314,116 @@ static int bt819_command(struct i2c_client *client, unsigned cmd, void *arg)
342 break; 314 break;
343 } 315 }
344 316
345 case DECODER_SET_OUTPUT: 317 case VIDIOC_STREAMON:
318 case VIDIOC_STREAMOFF:
346 { 319 {
347 int *iarg = arg; 320 int enable = cmd == VIDIOC_STREAMON;
348 321
349 v4l_dbg(1, debug, client, "set output %x\n", *iarg); 322 v4l_dbg(1, debug, client, "enable output %x\n", enable);
350 323
351 /* not much choice of outputs */ 324 if (decoder->enable != enable) {
352 if (*iarg != 0) 325 decoder->enable = enable;
353 return -EINVAL; 326 bt819_setbit(client, 0x16, 7, !enable);
327 }
354 break; 328 break;
355 } 329 }
356 330
357 case DECODER_ENABLE_OUTPUT: 331 case VIDIOC_QUERYCTRL:
358 { 332 {
359 int *iarg = arg; 333 struct v4l2_queryctrl *qc = arg;
360 int enable = (*iarg != 0);
361 334
362 v4l_dbg(1, debug, client, "enable output %x\n", *iarg); 335 switch (qc->id) {
336 case V4L2_CID_BRIGHTNESS:
337 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
338 break;
363 339
364 if (decoder->enable != enable) { 340 case V4L2_CID_CONTRAST:
365 decoder->enable = enable; 341 v4l2_ctrl_query_fill(qc, 0, 511, 1, 256);
366 bt819_setbit(client, 0x16, 7, !enable); 342 break;
343
344 case V4L2_CID_SATURATION:
345 v4l2_ctrl_query_fill(qc, 0, 511, 1, 256);
346 break;
347
348 case V4L2_CID_HUE:
349 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
350 break;
351
352 default:
353 return -EINVAL;
367 } 354 }
368 break; 355 break;
369 } 356 }
370 357
371 case DECODER_SET_PICTURE: 358 case VIDIOC_S_CTRL:
372 { 359 {
373 struct video_picture *pic = arg; 360 struct v4l2_control *ctrl = arg;
374 361
375 v4l_dbg(1, debug, client, 362 switch (ctrl->id) {
376 "set picture brightness %d contrast %d colour %d\n", 363 case V4L2_CID_BRIGHTNESS:
377 pic->brightness, pic->contrast, pic->colour); 364 if (decoder->bright != ctrl->value) {
365 decoder->bright = ctrl->value;
366 bt819_write(client, 0x0a, decoder->bright);
367 }
368 break;
378 369
370 case V4L2_CID_CONTRAST:
371 if (decoder->contrast != ctrl->value) {
372 decoder->contrast = ctrl->value;
373 bt819_write(client, 0x0c,
374 decoder->contrast & 0xff);
375 bt819_setbit(client, 0x0b, 2,
376 ((decoder->contrast >> 8) & 0x01));
377 }
378 break;
379 379
380 if (decoder->bright != pic->brightness) { 380 case V4L2_CID_SATURATION:
381 /* We want -128 to 127 we get 0-65535 */ 381 if (decoder->sat != ctrl->value) {
382 decoder->bright = pic->brightness; 382 decoder->sat = ctrl->value;
383 bt819_write(client, 0x0a, 383 bt819_write(client, 0x0d,
384 (decoder->bright >> 8) - 128); 384 (decoder->sat >> 7) & 0xff);
385 } 385 bt819_setbit(client, 0x0b, 1,
386 ((decoder->sat >> 15) & 0x01));
387
388 /* Ratio between U gain and V gain must stay the same as
389 the ratio between the default U and V gain values. */
390 temp = (decoder->sat * 180) / 254;
391 bt819_write(client, 0x0e, (temp >> 7) & 0xff);
392 bt819_setbit(client, 0x0b, 0, (temp >> 15) & 0x01);
393 }
394 break;
386 395
387 if (decoder->contrast != pic->contrast) { 396 case V4L2_CID_HUE:
388 /* We want 0 to 511 we get 0-65535 */ 397 if (decoder->hue != ctrl->value) {
389 decoder->contrast = pic->contrast; 398 decoder->hue = ctrl->value;
390 bt819_write(client, 0x0c, 399 bt819_write(client, 0x0f, decoder->hue);
391 (decoder->contrast >> 7) & 0xff); 400 }
392 bt819_setbit(client, 0x0b, 2, 401 break;
393 ((decoder->contrast >> 15) & 0x01)); 402 default:
403 return -EINVAL;
394 } 404 }
405 break;
406 }
395 407
396 if (decoder->sat != pic->colour) { 408 case VIDIOC_G_CTRL:
397 /* We want 0 to 511 we get 0-65535 */ 409 {
398 decoder->sat = pic->colour; 410 struct v4l2_control *ctrl = arg;
399 bt819_write(client, 0x0d,
400 (decoder->sat >> 7) & 0xff);
401 bt819_setbit(client, 0x0b, 1,
402 ((decoder->sat >> 15) & 0x01));
403
404 temp = (decoder->sat * 201) / 237;
405 bt819_write(client, 0x0e, (temp >> 7) & 0xff);
406 bt819_setbit(client, 0x0b, 0, (temp >> 15) & 0x01);
407 }
408 411
409 if (decoder->hue != pic->hue) { 412 switch (ctrl->id) {
410 /* We want -128 to 127 we get 0-65535 */ 413 case V4L2_CID_BRIGHTNESS:
411 decoder->hue = pic->hue; 414 ctrl->value = decoder->bright;
412 bt819_write(client, 0x0f, 415 break;
413 128 - (decoder->hue >> 8)); 416 case V4L2_CID_CONTRAST:
417 ctrl->value = decoder->contrast;
418 break;
419 case V4L2_CID_SATURATION:
420 ctrl->value = decoder->sat;
421 break;
422 case V4L2_CID_HUE:
423 ctrl->value = decoder->hue;
424 break;
425 default:
426 return -EINVAL;
414 } 427 }
415 break; 428 break;
416 } 429 }
@@ -462,13 +475,13 @@ static int bt819_probe(struct i2c_client *client,
462 decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL); 475 decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL);
463 if (decoder == NULL) 476 if (decoder == NULL)
464 return -ENOMEM; 477 return -ENOMEM;
465 decoder->norm = VIDEO_MODE_NTSC; 478 decoder->norm = V4L2_STD_NTSC;
466 decoder->input = 0; 479 decoder->input = 0;
467 decoder->enable = 1; 480 decoder->enable = 1;
468 decoder->bright = 32768; 481 decoder->bright = 0;
469 decoder->contrast = 32768; 482 decoder->contrast = 0xd8; /* 100% of original signal */
470 decoder->hue = 32768; 483 decoder->hue = 0;
471 decoder->sat = 32768; 484 decoder->sat = 0xfe; /* 100% of original signal */
472 decoder->initialized = 0; 485 decoder->initialized = 0;
473 i2c_set_clientdata(client, decoder); 486 i2c_set_clientdata(client, decoder);
474 487