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

[media] vpx3220: use 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
9a775323 6c45ec71

+51 -86
+51 -86
drivers/media/video/vpx3220.c
··· 28 28 #include <linux/videodev2.h> 29 29 #include <media/v4l2-device.h> 30 30 #include <media/v4l2-chip-ident.h> 31 + #include <media/v4l2-ctrls.h> 31 32 32 33 MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver"); 33 34 MODULE_AUTHOR("Laurent Pinchart"); ··· 45 44 46 45 struct vpx3220 { 47 46 struct v4l2_subdev sd; 47 + struct v4l2_ctrl_handler hdl; 48 48 unsigned char reg[255]; 49 49 50 50 v4l2_std_id norm; 51 51 int ident; 52 52 int input; 53 53 int enable; 54 - int bright; 55 - int contrast; 56 - int hue; 57 - int sat; 58 54 }; 59 55 60 56 static inline struct vpx3220 *to_vpx3220(struct v4l2_subdev *sd) 61 57 { 62 58 return container_of(sd, struct vpx3220, sd); 59 + } 60 + 61 + static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) 62 + { 63 + return &container_of(ctrl->handler, struct vpx3220, hdl)->sd; 63 64 } 64 65 65 66 static char *inputs[] = { "internal", "composite", "svideo" }; ··· 420 417 return 0; 421 418 } 422 419 423 - static int vpx3220_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) 420 + static int vpx3220_s_ctrl(struct v4l2_ctrl *ctrl) 424 421 { 425 - switch (qc->id) { 426 - case V4L2_CID_BRIGHTNESS: 427 - v4l2_ctrl_query_fill(qc, -128, 127, 1, 0); 428 - break; 429 - 430 - case V4L2_CID_CONTRAST: 431 - v4l2_ctrl_query_fill(qc, 0, 63, 1, 32); 432 - break; 433 - 434 - case V4L2_CID_SATURATION: 435 - v4l2_ctrl_query_fill(qc, 0, 4095, 1, 2048); 436 - break; 437 - 438 - case V4L2_CID_HUE: 439 - v4l2_ctrl_query_fill(qc, -512, 511, 1, 0); 440 - break; 441 - 442 - default: 443 - return -EINVAL; 444 - } 445 - return 0; 446 - } 447 - 448 - static int vpx3220_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 449 - { 450 - struct vpx3220 *decoder = to_vpx3220(sd); 422 + struct v4l2_subdev *sd = to_sd(ctrl); 451 423 452 424 switch (ctrl->id) { 453 425 case V4L2_CID_BRIGHTNESS: 454 - ctrl->value = decoder->bright; 455 - break; 426 + vpx3220_write(sd, 0xe6, ctrl->val); 427 + return 0; 456 428 case V4L2_CID_CONTRAST: 457 - ctrl->value = decoder->contrast; 458 - break; 429 + /* Bit 7 and 8 is for noise shaping */ 430 + vpx3220_write(sd, 0xe7, ctrl->val + 192); 431 + return 0; 459 432 case V4L2_CID_SATURATION: 460 - ctrl->value = decoder->sat; 461 - break; 433 + vpx3220_fp_write(sd, 0xa0, ctrl->val); 434 + return 0; 462 435 case V4L2_CID_HUE: 463 - ctrl->value = decoder->hue; 464 - break; 465 - default: 466 - return -EINVAL; 436 + vpx3220_fp_write(sd, 0x1c, ctrl->val); 437 + return 0; 467 438 } 468 - return 0; 469 - } 470 - 471 - static int vpx3220_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 472 - { 473 - struct vpx3220 *decoder = to_vpx3220(sd); 474 - 475 - switch (ctrl->id) { 476 - case V4L2_CID_BRIGHTNESS: 477 - if (decoder->bright != ctrl->value) { 478 - decoder->bright = ctrl->value; 479 - vpx3220_write(sd, 0xe6, decoder->bright); 480 - } 481 - break; 482 - case V4L2_CID_CONTRAST: 483 - if (decoder->contrast != ctrl->value) { 484 - /* Bit 7 and 8 is for noise shaping */ 485 - decoder->contrast = ctrl->value; 486 - vpx3220_write(sd, 0xe7, decoder->contrast + 192); 487 - } 488 - break; 489 - case V4L2_CID_SATURATION: 490 - if (decoder->sat != ctrl->value) { 491 - decoder->sat = ctrl->value; 492 - vpx3220_fp_write(sd, 0xa0, decoder->sat); 493 - } 494 - break; 495 - case V4L2_CID_HUE: 496 - if (decoder->hue != ctrl->value) { 497 - decoder->hue = ctrl->value; 498 - vpx3220_fp_write(sd, 0x1c, decoder->hue); 499 - } 500 - break; 501 - default: 502 - return -EINVAL; 503 - } 504 - return 0; 439 + return -EINVAL; 505 440 } 506 441 507 442 static int vpx3220_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) ··· 452 511 453 512 /* ----------------------------------------------------------------------- */ 454 513 514 + static const struct v4l2_ctrl_ops vpx3220_ctrl_ops = { 515 + .s_ctrl = vpx3220_s_ctrl, 516 + }; 517 + 455 518 static const struct v4l2_subdev_core_ops vpx3220_core_ops = { 456 519 .g_chip_ident = vpx3220_g_chip_ident, 457 520 .init = vpx3220_init, 458 - .g_ctrl = vpx3220_g_ctrl, 459 - .s_ctrl = vpx3220_s_ctrl, 460 - .queryctrl = vpx3220_queryctrl, 521 + .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 522 + .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 523 + .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 524 + .g_ctrl = v4l2_subdev_g_ctrl, 525 + .s_ctrl = v4l2_subdev_s_ctrl, 526 + .queryctrl = v4l2_subdev_queryctrl, 527 + .querymenu = v4l2_subdev_querymenu, 461 528 .s_std = vpx3220_s_std, 462 529 }; 463 530 ··· 507 558 decoder->norm = V4L2_STD_PAL; 508 559 decoder->input = 0; 509 560 decoder->enable = 1; 510 - decoder->bright = 32768; 511 - decoder->contrast = 32768; 512 - decoder->hue = 32768; 513 - decoder->sat = 32768; 561 + v4l2_ctrl_handler_init(&decoder->hdl, 4); 562 + v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, 563 + V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); 564 + v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, 565 + V4L2_CID_CONTRAST, 0, 63, 1, 32); 566 + v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, 567 + V4L2_CID_SATURATION, 0, 4095, 1, 2048); 568 + v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, 569 + V4L2_CID_HUE, -512, 511, 1, 0); 570 + sd->ctrl_handler = &decoder->hdl; 571 + if (decoder->hdl.error) { 572 + int err = decoder->hdl.error; 573 + 574 + v4l2_ctrl_handler_free(&decoder->hdl); 575 + kfree(decoder); 576 + return err; 577 + } 578 + v4l2_ctrl_handler_setup(&decoder->hdl); 514 579 515 580 ver = i2c_smbus_read_byte_data(client, 0x00); 516 581 pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) + ··· 562 599 static int vpx3220_remove(struct i2c_client *client) 563 600 { 564 601 struct v4l2_subdev *sd = i2c_get_clientdata(client); 602 + struct vpx3220 *decoder = to_vpx3220(sd); 565 603 566 604 v4l2_device_unregister_subdev(sd); 567 - kfree(to_vpx3220(sd)); 605 + v4l2_ctrl_handler_free(&decoder->hdl); 606 + kfree(decoder); 568 607 return 0; 569 608 } 570 609