Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

V4L/DVB (6419): V4L2 port of tda7432 from V4L1 api

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

+140 -130
+140 -130
drivers/media/video/tda7432.c
··· 8 8 * Muting and tone control by Jonathan Isom <jisom@ematic.com> 9 9 * 10 10 * Copyright (c) 2000 Eric Sandeen <eric_sandeen@bigfoot.com> 11 + * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org> 11 12 * This code is placed under the terms of the GNU General Public License 12 13 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu) 13 14 * Which was based on tda8425.c by Greg Alexander (c) 1998 ··· 277 276 t->volume = 0x3b ; /* -27dB Volume */ 278 277 if (loudness) /* Turn loudness on? */ 279 278 t->volume |= TDA7432_LD_ON; 280 - t->muted = VIDEO_AUDIO_MUTE; 279 + t->muted = 1; 281 280 t->treble = TDA7432_TREBLE_0DB; /* 0dB Treble */ 282 281 t->bass = TDA7432_BASS_0DB; /* 0dB Bass */ 283 282 t->lf = TDA7432_ATTEN_0DB; /* 0dB attenuation */ ··· 333 332 return 0; 334 333 } 335 334 335 + static int tda7432_get_ctrl(struct i2c_client *client, 336 + struct v4l2_control *ctrl) 337 + { 338 + struct tda7432 *t = i2c_get_clientdata(client); 339 + 340 + switch (ctrl->id) { 341 + case V4L2_CID_AUDIO_MUTE: 342 + ctrl->value=t->muted; 343 + return 0; 344 + case V4L2_CID_AUDIO_VOLUME: 345 + if (!maxvol){ /* max +20db */ 346 + ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 630; 347 + } else { /* max 0db */ 348 + ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 829; 349 + } 350 + return 0; 351 + case V4L2_CID_AUDIO_BALANCE: 352 + { 353 + if ( (t->lf) < (t->rf) ) 354 + /* right is attenuated, balance shifted left */ 355 + ctrl->value = (32768 - 1057*(t->rf)); 356 + else 357 + /* left is attenuated, balance shifted right */ 358 + ctrl->value = (32768 + 1057*(t->lf)); 359 + return 0; 360 + } 361 + case V4L2_CID_AUDIO_BASS: 362 + { 363 + /* Bass/treble 4 bits each */ 364 + int bass=t->bass; 365 + if(bass >= 0x8) 366 + bass = ~(bass - 0x8) & 0xf; 367 + ctrl->value = (bass << 12)+(bass << 8)+(bass << 4)+(bass); 368 + return 0; 369 + } 370 + case V4L2_CID_AUDIO_TREBLE: 371 + { 372 + int treble=t->treble; 373 + if(treble >= 0x8) 374 + treble = ~(treble - 0x8) & 0xf; 375 + ctrl->value = (treble << 12)+(treble << 8)+(treble << 4)+(treble); 376 + return 0; 377 + } 378 + } 379 + return -EINVAL; 380 + } 381 + 382 + static int tda7432_set_ctrl(struct i2c_client *client, 383 + struct v4l2_control *ctrl) 384 + { 385 + struct tda7432 *t = i2c_get_clientdata(client); 386 + 387 + switch (ctrl->id) { 388 + case V4L2_CID_AUDIO_MUTE: 389 + t->muted=ctrl->value; 390 + break; 391 + case V4L2_CID_AUDIO_VOLUME: 392 + if(!maxvol){ /* max +20db */ 393 + t->volume = 0x6f - ((ctrl->value)/630); 394 + } else { /* max 0db */ 395 + t->volume = 0x6f - ((ctrl->value)/829); 396 + } 397 + if (loudness) /* Turn on the loudness bit */ 398 + t->volume |= TDA7432_LD_ON; 399 + 400 + tda7432_write(client,TDA7432_VL, t->volume); 401 + return 0; 402 + case V4L2_CID_AUDIO_BALANCE: 403 + if (ctrl->value < 32768) { 404 + /* shifted to left, attenuate right */ 405 + t->rr = (32768 - ctrl->value)/1057; 406 + t->rf = t->rr; 407 + t->lr = TDA7432_ATTEN_0DB; 408 + t->lf = TDA7432_ATTEN_0DB; 409 + } else if(ctrl->value > 32769) { 410 + /* shifted to right, attenuate left */ 411 + t->lf = (ctrl->value - 32768)/1057; 412 + t->lr = t->lf; 413 + t->rr = TDA7432_ATTEN_0DB; 414 + t->rf = TDA7432_ATTEN_0DB; 415 + } else { 416 + /* centered */ 417 + t->rr = TDA7432_ATTEN_0DB; 418 + t->rf = TDA7432_ATTEN_0DB; 419 + t->lf = TDA7432_ATTEN_0DB; 420 + t->lr = TDA7432_ATTEN_0DB; 421 + } 422 + break; 423 + case V4L2_CID_AUDIO_BASS: 424 + t->bass = ctrl->value >> 12; 425 + if(t->bass>= 0x8) 426 + t->bass = (~t->bass & 0xf) + 0x8 ; 427 + 428 + tda7432_write(client,TDA7432_TN, 0x10 | (t->bass << 4) | t->treble ); 429 + return 0; 430 + case V4L2_CID_AUDIO_TREBLE: 431 + t->treble= ctrl->value >> 12; 432 + if(t->treble>= 0x8) 433 + t->treble = (~t->treble & 0xf) + 0x8 ; 434 + 435 + tda7432_write(client,TDA7432_TN, 0x10 | (t->bass << 4) | t->treble ); 436 + return 0; 437 + default: 438 + return -EINVAL; 439 + } 440 + 441 + /* Used for both mute and balance changes */ 442 + if (t->muted) 443 + { 444 + /* Mute & update balance*/ 445 + tda7432_write(client,TDA7432_LF, t->lf | TDA7432_MUTE); 446 + tda7432_write(client,TDA7432_LR, t->lr | TDA7432_MUTE); 447 + tda7432_write(client,TDA7432_RF, t->rf | TDA7432_MUTE); 448 + tda7432_write(client,TDA7432_RR, t->rr | TDA7432_MUTE); 449 + } else { 450 + tda7432_write(client,TDA7432_LF, t->lf); 451 + tda7432_write(client,TDA7432_LR, t->lr); 452 + tda7432_write(client,TDA7432_RF, t->rf); 453 + tda7432_write(client,TDA7432_RR, t->rr); 454 + } 455 + return 0; 456 + } 457 + 336 458 static int tda7432_command(struct i2c_client *client, 337 459 unsigned int cmd, void *arg) 338 460 { 339 - struct tda7432 *t = i2c_get_clientdata(client); 340 461 v4l_dbg(2, debug,client,"In tda7432_command\n"); 341 462 if (debug>1) 342 463 v4l_i2c_print_ioctl(client,cmd); ··· 467 344 /* --- v4l ioctls --- */ 468 345 /* take care: bttv does userspace copying, we'll get a 469 346 kernel pointer here... */ 470 - 471 - /* Query card - scale from TDA7432 settings to V4L settings */ 472 - case VIDIOCGAUDIO: 347 + case VIDIOC_QUERYCTRL: 473 348 { 474 - struct video_audio *va = arg; 349 + struct v4l2_queryctrl *qc = arg; 475 350 476 - va->flags |= VIDEO_AUDIO_VOLUME | 477 - VIDEO_AUDIO_BASS | 478 - VIDEO_AUDIO_TREBLE | 479 - VIDEO_AUDIO_MUTABLE; 480 - if (t->muted) 481 - va->flags |= VIDEO_AUDIO_MUTE; 482 - va->mode |= VIDEO_SOUND_STEREO; 483 - /* Master volume control 484 - * V4L volume is min 0, max 65535 485 - * TDA7432 Volume: 486 - * Min (-79dB) is 0x6f 487 - * Max (+20dB) is 0x07 (630) 488 - * Max (0dB) is 0x20 (829) 489 - * (Mask out bit 7 of vol - it's for the loudness setting) 490 - */ 491 - if (!maxvol){ /* max +20db */ 492 - va->volume = ( 0x6f - (t->volume & 0x7F) ) * 630; 493 - } else { /* max 0db */ 494 - va->volume = ( 0x6f - (t->volume & 0x7F) ) * 829; 351 + switch (qc->id) { 352 + case V4L2_CID_AUDIO_MUTE: 353 + case V4L2_CID_AUDIO_VOLUME: 354 + case V4L2_CID_AUDIO_BALANCE: 355 + case V4L2_CID_AUDIO_BASS: 356 + case V4L2_CID_AUDIO_TREBLE: 357 + default: 358 + return -EINVAL; 495 359 } 496 - 497 - /* Balance depends on L,R attenuation 498 - * V4L balance is 0 to 65535, middle is 32768 499 - * TDA7432 attenuation: min (0dB) is 0, max (-37.5dB) is 0x1f 500 - * to scale up to V4L numbers, mult by 1057 501 - * attenuation exists for lf, lr, rf, rr 502 - * we use only lf and rf (front channels) 503 - */ 504 - 505 - if ( (t->lf) < (t->rf) ) 506 - /* right is attenuated, balance shifted left */ 507 - va->balance = (32768 - 1057*(t->rf)); 508 - else 509 - /* left is attenuated, balance shifted right */ 510 - va->balance = (32768 + 1057*(t->lf)); 511 - 512 - /* Bass/treble 4 bits each */ 513 - va->bass=t->bass; 514 - if(va->bass >= 0x8) 515 - va->bass = ~(va->bass - 0x8) & 0xf; 516 - va->bass = (va->bass << 12)+(va->bass << 8)+(va->bass << 4)+(va->bass); 517 - va->treble=t->treble; 518 - if(va->treble >= 0x8) 519 - va->treble = ~(va->treble - 0x8) & 0xf; 520 - va->treble = (va->treble << 12)+(va->treble << 8)+(va->treble << 4)+(va->treble); 521 - 522 - break; /* VIDIOCGAUDIO case */ 360 + return v4l2_ctrl_query_fill_std(qc); 523 361 } 362 + case VIDIOC_S_CTRL: 363 + return tda7432_set_ctrl(client, arg); 524 364 525 - /* Set card - scale from V4L settings to TDA7432 settings */ 526 - case VIDIOCSAUDIO: 527 - { 528 - struct video_audio *va = arg; 529 - 530 - if(va->flags & VIDEO_AUDIO_VOLUME){ 531 - if(!maxvol){ /* max +20db */ 532 - t->volume = 0x6f - ((va->volume)/630); 533 - } else { /* max 0db */ 534 - t->volume = 0x6f - ((va->volume)/829); 535 - } 536 - 537 - if (loudness) /* Turn on the loudness bit */ 538 - t->volume |= TDA7432_LD_ON; 539 - 540 - tda7432_write(client,TDA7432_VL, t->volume); 541 - } 542 - 543 - if(va->flags & VIDEO_AUDIO_BASS) 544 - { 545 - t->bass = va->bass >> 12; 546 - if(t->bass>= 0x8) 547 - t->bass = (~t->bass & 0xf) + 0x8 ; 548 - } 549 - if(va->flags & VIDEO_AUDIO_TREBLE) 550 - { 551 - t->treble= va->treble >> 12; 552 - if(t->treble>= 0x8) 553 - t->treble = (~t->treble & 0xf) + 0x8 ; 554 - } 555 - if(va->flags & (VIDEO_AUDIO_TREBLE| VIDEO_AUDIO_BASS)) 556 - tda7432_write(client,TDA7432_TN, 0x10 | (t->bass << 4) | t->treble ); 557 - 558 - if(va->flags & VIDEO_AUDIO_BALANCE) { 559 - if (va->balance < 32768) 560 - { 561 - /* shifted to left, attenuate right */ 562 - t->rr = (32768 - va->balance)/1057; 563 - t->rf = t->rr; 564 - t->lr = TDA7432_ATTEN_0DB; 565 - t->lf = TDA7432_ATTEN_0DB; 566 - } 567 - else if(va->balance > 32769) 568 - { 569 - /* shifted to right, attenuate left */ 570 - t->lf = (va->balance - 32768)/1057; 571 - t->lr = t->lf; 572 - t->rr = TDA7432_ATTEN_0DB; 573 - t->rf = TDA7432_ATTEN_0DB; 574 - } 575 - else 576 - { 577 - /* centered */ 578 - t->rr = TDA7432_ATTEN_0DB; 579 - t->rf = TDA7432_ATTEN_0DB; 580 - t->lf = TDA7432_ATTEN_0DB; 581 - t->lr = TDA7432_ATTEN_0DB; 582 - } 583 - } 584 - 585 - t->muted=(va->flags & VIDEO_AUDIO_MUTE); 586 - if (t->muted) 587 - { 588 - /* Mute & update balance*/ 589 - tda7432_write(client,TDA7432_LF, t->lf | TDA7432_MUTE); 590 - tda7432_write(client,TDA7432_LR, t->lr | TDA7432_MUTE); 591 - tda7432_write(client,TDA7432_RF, t->rf | TDA7432_MUTE); 592 - tda7432_write(client,TDA7432_RR, t->rr | TDA7432_MUTE); 593 - } else { 594 - tda7432_write(client,TDA7432_LF, t->lf); 595 - tda7432_write(client,TDA7432_LR, t->lr); 596 - tda7432_write(client,TDA7432_RF, t->rf); 597 - tda7432_write(client,TDA7432_RR, t->rr); 598 - } 599 - 600 - break; 601 - 602 - } /* end of VIDEOCSAUDIO case */ 365 + case VIDIOC_G_CTRL: 366 + return tda7432_get_ctrl(client, arg); 603 367 604 368 } /* end of (cmd) switch */ 605 369