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

V4L/DVB: msp3400: convert to the new control framework

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
ebc3bba5 e3560543

+109 -171
+87 -159
drivers/media/video/msp3400-driver.c
··· 283 283 msp_write_dem(client, 0x40, state->i2s_mode); 284 284 } 285 285 286 - void msp_set_audio(struct i2c_client *client) 287 - { 288 - struct msp_state *state = to_state(i2c_get_clientdata(client)); 289 - int bal = 0, bass, treble, loudness; 290 - int val = 0; 291 - int reallymuted = state->muted | state->scan_in_progress; 292 - 293 - if (!reallymuted) 294 - val = (state->volume * 0x7f / 65535) << 8; 295 - 296 - v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n", 297 - state->muted ? "on" : "off", 298 - state->scan_in_progress ? "yes" : "no", 299 - state->volume); 300 - 301 - msp_write_dsp(client, 0x0000, val); 302 - msp_write_dsp(client, 0x0007, reallymuted ? 0x1 : (val | 0x1)); 303 - if (state->has_scart2_out_volume) 304 - msp_write_dsp(client, 0x0040, reallymuted ? 0x1 : (val | 0x1)); 305 - if (state->has_headphones) 306 - msp_write_dsp(client, 0x0006, val); 307 - if (!state->has_sound_processing) 308 - return; 309 - 310 - if (val) 311 - bal = (u8)((state->balance / 256) - 128); 312 - bass = ((state->bass - 32768) * 0x60 / 65535) << 8; 313 - treble = ((state->treble - 32768) * 0x60 / 65535) << 8; 314 - loudness = state->loudness ? ((5 * 4) << 8) : 0; 315 - 316 - v4l_dbg(1, msp_debug, client, "balance=%d bass=%d treble=%d loudness=%d\n", 317 - state->balance, state->bass, state->treble, state->loudness); 318 - 319 - msp_write_dsp(client, 0x0001, bal << 8); 320 - msp_write_dsp(client, 0x0002, bass); 321 - msp_write_dsp(client, 0x0003, treble); 322 - msp_write_dsp(client, 0x0004, loudness); 323 - if (!state->has_headphones) 324 - return; 325 - msp_write_dsp(client, 0x0030, bal << 8); 326 - msp_write_dsp(client, 0x0031, bass); 327 - msp_write_dsp(client, 0x0032, treble); 328 - msp_write_dsp(client, 0x0033, loudness); 329 - } 330 - 331 286 /* ------------------------------------------------------------------------ */ 332 287 333 288 static void msp_wake_thread(struct i2c_client *client) ··· 318 363 319 364 /* ------------------------------------------------------------------------ */ 320 365 321 - static int msp_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 366 + static int msp_s_ctrl(struct v4l2_ctrl *ctrl) 322 367 { 323 - struct msp_state *state = to_state(sd); 368 + struct msp_state *state = ctrl_to_state(ctrl); 369 + struct i2c_client *client = v4l2_get_subdevdata(&state->sd); 370 + int val = ctrl->val; 324 371 325 372 switch (ctrl->id) { 326 - case V4L2_CID_AUDIO_VOLUME: 327 - ctrl->value = state->volume; 328 - break; 373 + case V4L2_CID_AUDIO_VOLUME: { 374 + /* audio volume cluster */ 375 + int reallymuted = state->muted->val | state->scan_in_progress; 329 376 330 - case V4L2_CID_AUDIO_MUTE: 331 - ctrl->value = state->muted; 332 - break; 377 + if (!reallymuted) 378 + val = (val * 0x7f / 65535) << 8; 333 379 334 - case V4L2_CID_AUDIO_BALANCE: 335 - if (!state->has_sound_processing) 336 - return -EINVAL; 337 - ctrl->value = state->balance; 380 + v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n", 381 + state->muted->val ? "on" : "off", 382 + state->scan_in_progress ? "yes" : "no", 383 + state->volume->val); 384 + 385 + msp_write_dsp(client, 0x0000, val); 386 + msp_write_dsp(client, 0x0007, reallymuted ? 0x1 : (val | 0x1)); 387 + if (state->has_scart2_out_volume) 388 + msp_write_dsp(client, 0x0040, reallymuted ? 0x1 : (val | 0x1)); 389 + if (state->has_headphones) 390 + msp_write_dsp(client, 0x0006, val); 338 391 break; 392 + } 339 393 340 394 case V4L2_CID_AUDIO_BASS: 341 - if (!state->has_sound_processing) 342 - return -EINVAL; 343 - ctrl->value = state->bass; 395 + val = ((val - 32768) * 0x60 / 65535) << 8; 396 + msp_write_dsp(client, 0x0002, val); 397 + if (state->has_headphones) 398 + msp_write_dsp(client, 0x0031, val); 344 399 break; 345 400 346 401 case V4L2_CID_AUDIO_TREBLE: 347 - if (!state->has_sound_processing) 348 - return -EINVAL; 349 - ctrl->value = state->treble; 402 + val = ((val - 32768) * 0x60 / 65535) << 8; 403 + msp_write_dsp(client, 0x0003, val); 404 + if (state->has_headphones) 405 + msp_write_dsp(client, 0x0032, val); 350 406 break; 351 407 352 408 case V4L2_CID_AUDIO_LOUDNESS: 353 - if (!state->has_sound_processing) 354 - return -EINVAL; 355 - ctrl->value = state->loudness; 409 + val = val ? ((5 * 4) << 8) : 0; 410 + msp_write_dsp(client, 0x0004, val); 411 + if (state->has_headphones) 412 + msp_write_dsp(client, 0x0033, val); 413 + break; 414 + 415 + case V4L2_CID_AUDIO_BALANCE: 416 + val = (u8)((val / 256) - 128); 417 + msp_write_dsp(client, 0x0001, val << 8); 418 + if (state->has_headphones) 419 + msp_write_dsp(client, 0x0030, val << 8); 356 420 break; 357 421 358 422 default: ··· 380 406 return 0; 381 407 } 382 408 383 - static int msp_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 409 + void msp_update_volume(struct msp_state *state) 384 410 { 385 - struct msp_state *state = to_state(sd); 386 - struct i2c_client *client = v4l2_get_subdevdata(sd); 387 - 388 - switch (ctrl->id) { 389 - case V4L2_CID_AUDIO_VOLUME: 390 - state->volume = ctrl->value; 391 - if (state->volume == 0) 392 - state->balance = 32768; 393 - break; 394 - 395 - case V4L2_CID_AUDIO_MUTE: 396 - if (ctrl->value < 0 || ctrl->value >= 2) 397 - return -ERANGE; 398 - state->muted = ctrl->value; 399 - break; 400 - 401 - case V4L2_CID_AUDIO_BASS: 402 - if (!state->has_sound_processing) 403 - return -EINVAL; 404 - state->bass = ctrl->value; 405 - break; 406 - 407 - case V4L2_CID_AUDIO_TREBLE: 408 - if (!state->has_sound_processing) 409 - return -EINVAL; 410 - state->treble = ctrl->value; 411 - break; 412 - 413 - case V4L2_CID_AUDIO_LOUDNESS: 414 - if (!state->has_sound_processing) 415 - return -EINVAL; 416 - state->loudness = ctrl->value; 417 - break; 418 - 419 - case V4L2_CID_AUDIO_BALANCE: 420 - if (!state->has_sound_processing) 421 - return -EINVAL; 422 - state->balance = ctrl->value; 423 - break; 424 - 425 - default: 426 - return -EINVAL; 427 - } 428 - msp_set_audio(client); 429 - return 0; 411 + v4l2_ctrl_s_ctrl(state->volume, v4l2_ctrl_g_ctrl(state->volume)); 430 412 } 431 413 432 414 /* --- v4l2 ioctls --- */ ··· 402 472 msp3400c_set_mode(client, MSP_MODE_FM_RADIO); 403 473 msp3400c_set_carrier(client, MSP_CARRIER(10.7), 404 474 MSP_CARRIER(10.7)); 405 - msp_set_audio(client); 475 + msp_update_volume(state); 406 476 break; 407 477 case OPMODE_AUTODETECT: 408 478 case OPMODE_AUTOSELECT: ··· 522 592 return 0; 523 593 } 524 594 525 - static int msp_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) 526 - { 527 - struct msp_state *state = to_state(sd); 528 - 529 - switch (qc->id) { 530 - case V4L2_CID_AUDIO_VOLUME: 531 - return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880); 532 - case V4L2_CID_AUDIO_MUTE: 533 - return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); 534 - default: 535 - break; 536 - } 537 - if (!state->has_sound_processing) 538 - return -EINVAL; 539 - switch (qc->id) { 540 - case V4L2_CID_AUDIO_LOUDNESS: 541 - return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); 542 - case V4L2_CID_AUDIO_BALANCE: 543 - case V4L2_CID_AUDIO_BASS: 544 - case V4L2_CID_AUDIO_TREBLE: 545 - return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768); 546 - default: 547 - return -EINVAL; 548 - } 549 - return 0; 550 - } 551 - 552 595 static int msp_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 553 596 { 554 597 struct msp_state *state = to_state(sd); ··· 536 633 struct msp_state *state = to_state(sd); 537 634 struct i2c_client *client = v4l2_get_subdevdata(sd); 538 635 const char *p; 636 + char prefix[V4L2_SUBDEV_NAME_SIZE + 20]; 539 637 540 638 if (state->opmode == OPMODE_AUTOSELECT) 541 639 msp_detect_stereo(client); 542 640 v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n", 543 641 client->name, state->rev1, state->rev2); 544 - v4l_info(client, "Audio: volume %d%s\n", 545 - state->volume, state->muted ? " (muted)" : ""); 546 - if (state->has_sound_processing) { 547 - v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n", 548 - state->balance, state->bass, 549 - state->treble, 550 - state->loudness ? "on" : "off"); 551 - } 642 + snprintf(prefix, sizeof(prefix), "%s: Audio: ", sd->name); 643 + v4l2_ctrl_handler_log_status(&state->hdl, prefix); 552 644 switch (state->mode) { 553 645 case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break; 554 646 case MSP_MODE_FM_RADIO: p = "FM Radio"; break; ··· 593 695 594 696 /* ----------------------------------------------------------------------- */ 595 697 698 + static const struct v4l2_ctrl_ops msp_ctrl_ops = { 699 + .s_ctrl = msp_s_ctrl, 700 + }; 701 + 596 702 static const struct v4l2_subdev_core_ops msp_core_ops = { 597 703 .log_status = msp_log_status, 598 704 .g_chip_ident = msp_g_chip_ident, 599 - .g_ctrl = msp_g_ctrl, 600 - .s_ctrl = msp_s_ctrl, 601 - .queryctrl = msp_queryctrl, 705 + .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 706 + .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 707 + .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 708 + .g_ctrl = v4l2_subdev_g_ctrl, 709 + .s_ctrl = v4l2_subdev_s_ctrl, 710 + .queryctrl = v4l2_subdev_queryctrl, 711 + .querymenu = v4l2_subdev_querymenu, 602 712 .s_std = msp_s_std, 603 713 }; 604 714 ··· 634 728 { 635 729 struct msp_state *state; 636 730 struct v4l2_subdev *sd; 731 + struct v4l2_ctrl_handler *hdl; 637 732 int (*thread_func)(void *data) = NULL; 638 733 int msp_hard; 639 734 int msp_family; ··· 659 752 660 753 state->v4l2_std = V4L2_STD_NTSC; 661 754 state->audmode = V4L2_TUNER_MODE_STEREO; 662 - state->volume = 58880; /* 0db gain */ 663 - state->balance = 32768; /* 0db gain */ 664 - state->bass = 32768; 665 - state->treble = 32768; 666 - state->loudness = 0; 667 755 state->input = -1; 668 - state->muted = 0; 669 756 state->i2s_mode = 0; 670 757 init_waitqueue_head(&state->wq); 671 758 /* These are the reset input/output positions */ ··· 677 776 kfree(state); 678 777 return -ENODEV; 679 778 } 680 - 681 - msp_set_audio(client); 682 779 683 780 msp_family = ((state->rev1 >> 4) & 0x0f) + 3; 684 781 msp_product = (state->rev2 >> 8) & 0xff; ··· 748 849 state->opmode = OPMODE_MANUAL; 749 850 } 750 851 852 + hdl = &state->hdl; 853 + v4l2_ctrl_handler_init(hdl, 6); 854 + if (state->has_sound_processing) { 855 + v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, 856 + V4L2_CID_AUDIO_BASS, 0, 65535, 65535 / 100, 32768); 857 + v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, 858 + V4L2_CID_AUDIO_TREBLE, 0, 65535, 65535 / 100, 32768); 859 + v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, 860 + V4L2_CID_AUDIO_LOUDNESS, 0, 1, 1, 0); 861 + } 862 + state->volume = v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, 863 + V4L2_CID_AUDIO_VOLUME, 0, 65535, 65535 / 100, 58880); 864 + v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, 865 + V4L2_CID_AUDIO_BALANCE, 0, 65535, 65535 / 100, 32768); 866 + state->muted = v4l2_ctrl_new_std(hdl, &msp_ctrl_ops, 867 + V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0); 868 + sd->ctrl_handler = hdl; 869 + if (hdl->error) { 870 + int err = hdl->error; 871 + 872 + v4l2_ctrl_handler_free(hdl); 873 + kfree(state); 874 + return err; 875 + } 876 + 877 + v4l2_ctrl_cluster(2, &state->volume); 878 + v4l2_ctrl_handler_setup(hdl); 879 + 751 880 /* hello world :-) */ 752 881 v4l_info(client, "MSP%d4%02d%c-%c%d found @ 0x%x (%s)\n", 753 882 msp_family, msp_product, ··· 830 903 } 831 904 msp_reset(client); 832 905 906 + v4l2_ctrl_handler_free(&state->hdl); 833 907 kfree(state); 834 908 return 0; 835 909 }
+14 -4
drivers/media/video/msp3400-driver.h
··· 6 6 7 7 #include <media/msp3400.h> 8 8 #include <media/v4l2-device.h> 9 + #include <media/v4l2-ctrls.h> 9 10 10 11 /* ---------------------------------------------------------------------- */ 11 12 ··· 52 51 53 52 struct msp_state { 54 53 struct v4l2_subdev sd; 54 + struct v4l2_ctrl_handler hdl; 55 55 int rev1, rev2; 56 56 int ident; 57 57 u8 has_nicam; ··· 89 87 int audmode; 90 88 int rxsubchans; 91 89 92 - int volume, muted; 93 - int balance, loudness; 94 - int bass, treble; 90 + struct { 91 + /* volume cluster */ 92 + struct v4l2_ctrl *volume; 93 + struct v4l2_ctrl *muted; 94 + }; 95 + 95 96 int scan_in_progress; 96 97 97 98 /* thread */ ··· 109 104 return container_of(sd, struct msp_state, sd); 110 105 } 111 106 107 + static inline struct msp_state *ctrl_to_state(struct v4l2_ctrl *ctrl) 108 + { 109 + return container_of(ctrl->handler, struct msp_state, hdl); 110 + } 111 + 112 112 /* msp3400-driver.c */ 113 113 int msp_write_dem(struct i2c_client *client, int addr, int val); 114 114 int msp_write_dsp(struct i2c_client *client, int addr, int val); ··· 121 111 int msp_read_dsp(struct i2c_client *client, int addr); 122 112 int msp_reset(struct i2c_client *client); 123 113 void msp_set_scart(struct i2c_client *client, int in, int out); 124 - void msp_set_audio(struct i2c_client *client); 114 + void msp_update_volume(struct msp_state *state); 125 115 int msp_sleep(struct msp_state *state, int timeout); 126 116 127 117 /* msp3400-kthreads.c */
+8 -8
drivers/media/video/msp3400-kthreads.c
··· 496 496 v4l_dbg(1, msp_debug, client, 497 497 "thread: no carrier scan\n"); 498 498 state->scan_in_progress = 0; 499 - msp_set_audio(client); 499 + msp_update_volume(state); 500 500 continue; 501 501 } 502 502 503 503 /* mute audio */ 504 504 state->scan_in_progress = 1; 505 - msp_set_audio(client); 505 + msp_update_volume(state); 506 506 507 507 msp3400c_set_mode(client, MSP_MODE_AM_DETECT); 508 508 val1 = val2 = 0; ··· 634 634 /* unmute */ 635 635 state->scan_in_progress = 0; 636 636 msp3400c_set_audmode(client); 637 - msp_set_audio(client); 637 + msp_update_volume(state); 638 638 639 639 if (msp_debug) 640 640 msp3400c_print_mode(client); ··· 679 679 v4l_dbg(1, msp_debug, client, 680 680 "thread: no carrier scan\n"); 681 681 state->scan_in_progress = 0; 682 - msp_set_audio(client); 682 + msp_update_volume(state); 683 683 continue; 684 684 } 685 685 686 686 /* mute audio */ 687 687 state->scan_in_progress = 1; 688 - msp_set_audio(client); 688 + msp_update_volume(state); 689 689 690 690 /* start autodetect. Note: autodetect is not supported for 691 691 NTSC-M and radio, hence we force the standard in those ··· 797 797 /* unmute */ 798 798 msp3400c_set_audmode(client); 799 799 state->scan_in_progress = 0; 800 - msp_set_audio(client); 800 + msp_update_volume(state); 801 801 802 802 /* monitor tv audio mode, the first time don't wait 803 803 so long to get a quick stereo/bilingual result */ ··· 974 974 v4l_dbg(1, msp_debug, client, 975 975 "thread: no carrier scan\n"); 976 976 state->scan_in_progress = 0; 977 - msp_set_audio(client); 977 + msp_update_volume(state); 978 978 continue; 979 979 } 980 980 ··· 1020 1020 } 1021 1021 1022 1022 /* unmute: dispatch sound to scart output, set scart volume */ 1023 - msp_set_audio(client); 1023 + msp_update_volume(state); 1024 1024 1025 1025 /* restore ACB */ 1026 1026 if (msp_write_dsp(client, 0x13, state->acb))