diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2013-02-03 06:34:18 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-06-17 08:27:28 -0400 |
commit | 16b371784ecf1a2d1d7f04760807b3b8138d369f (patch) | |
tree | dfa864c6e433dffd7f8a0976b4efad493710e53f /drivers/media/radio/radio-tea5764.c | |
parent | cf9033f9b5d867ae040d37a148cf1c1e645ffe96 (diff) |
[media] radio-tea5764: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Fabio Belavenuto <belavenuto@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/radio/radio-tea5764.c')
-rw-r--r-- | drivers/media/radio/radio-tea5764.c | 79 |
1 files changed, 26 insertions, 53 deletions
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c index 4e0bf644b4f9..5c47a970843e 100644 --- a/drivers/media/radio/radio-tea5764.c +++ b/drivers/media/radio/radio-tea5764.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <media/v4l2-common.h> | 40 | #include <media/v4l2-common.h> |
41 | #include <media/v4l2-ioctl.h> | 41 | #include <media/v4l2-ioctl.h> |
42 | #include <media/v4l2-device.h> | 42 | #include <media/v4l2-device.h> |
43 | #include <media/v4l2-ctrls.h> | ||
43 | 44 | ||
44 | #define DRIVER_VERSION "0.0.2" | 45 | #define DRIVER_VERSION "0.0.2" |
45 | 46 | ||
@@ -139,7 +140,8 @@ static int radio_nr = -1; | |||
139 | static int use_xtal = RADIO_TEA5764_XTAL; | 140 | static int use_xtal = RADIO_TEA5764_XTAL; |
140 | 141 | ||
141 | struct tea5764_device { | 142 | struct tea5764_device { |
142 | struct v4l2_device v4l2_dev; | 143 | struct v4l2_device v4l2_dev; |
144 | struct v4l2_ctrl_handler ctrl_handler; | ||
143 | struct i2c_client *i2c_client; | 145 | struct i2c_client *i2c_client; |
144 | struct video_device vdev; | 146 | struct video_device vdev; |
145 | struct tea5764_regs regs; | 147 | struct tea5764_regs regs; |
@@ -189,18 +191,6 @@ static int tea5764_i2c_write(struct tea5764_device *radio) | |||
189 | return 0; | 191 | return 0; |
190 | } | 192 | } |
191 | 193 | ||
192 | /* V4L2 code related */ | ||
193 | static struct v4l2_queryctrl radio_qctrl[] = { | ||
194 | { | ||
195 | .id = V4L2_CID_AUDIO_MUTE, | ||
196 | .name = "Mute", | ||
197 | .minimum = 0, | ||
198 | .maximum = 1, | ||
199 | .default_value = 1, | ||
200 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
201 | } | ||
202 | }; | ||
203 | |||
204 | static void tea5764_power_up(struct tea5764_device *radio) | 194 | static void tea5764_power_up(struct tea5764_device *radio) |
205 | { | 195 | { |
206 | struct tea5764_regs *r = &radio->regs; | 196 | struct tea5764_regs *r = &radio->regs; |
@@ -293,11 +283,6 @@ static void tea5764_mute(struct tea5764_device *radio, int on) | |||
293 | tea5764_i2c_write(radio); | 283 | tea5764_i2c_write(radio); |
294 | } | 284 | } |
295 | 285 | ||
296 | static int tea5764_is_muted(struct tea5764_device *radio) | ||
297 | { | ||
298 | return radio->regs.tnctrl & TEA5764_TNCTRL_MU; | ||
299 | } | ||
300 | |||
301 | /* V4L2 vidioc */ | 286 | /* V4L2 vidioc */ |
302 | static int vidioc_querycap(struct file *file, void *priv, | 287 | static int vidioc_querycap(struct file *file, void *priv, |
303 | struct v4l2_capability *v) | 288 | struct v4l2_capability *v) |
@@ -391,42 +376,14 @@ static int vidioc_g_frequency(struct file *file, void *priv, | |||
391 | return 0; | 376 | return 0; |
392 | } | 377 | } |
393 | 378 | ||
394 | static int vidioc_queryctrl(struct file *file, void *priv, | 379 | static int tea5764_s_ctrl(struct v4l2_ctrl *ctrl) |
395 | struct v4l2_queryctrl *qc) | ||
396 | { | ||
397 | int i; | ||
398 | |||
399 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { | ||
400 | if (qc->id && qc->id == radio_qctrl[i].id) { | ||
401 | memcpy(qc, &(radio_qctrl[i]), sizeof(*qc)); | ||
402 | return 0; | ||
403 | } | ||
404 | } | ||
405 | return -EINVAL; | ||
406 | } | ||
407 | |||
408 | static int vidioc_g_ctrl(struct file *file, void *priv, | ||
409 | struct v4l2_control *ctrl) | ||
410 | { | ||
411 | struct tea5764_device *radio = video_drvdata(file); | ||
412 | |||
413 | switch (ctrl->id) { | ||
414 | case V4L2_CID_AUDIO_MUTE: | ||
415 | tea5764_i2c_read(radio); | ||
416 | ctrl->value = tea5764_is_muted(radio) ? 1 : 0; | ||
417 | return 0; | ||
418 | } | ||
419 | return -EINVAL; | ||
420 | } | ||
421 | |||
422 | static int vidioc_s_ctrl(struct file *file, void *priv, | ||
423 | struct v4l2_control *ctrl) | ||
424 | { | 380 | { |
425 | struct tea5764_device *radio = video_drvdata(file); | 381 | struct tea5764_device *radio = |
382 | container_of(ctrl->handler, struct tea5764_device, ctrl_handler); | ||
426 | 383 | ||
427 | switch (ctrl->id) { | 384 | switch (ctrl->id) { |
428 | case V4L2_CID_AUDIO_MUTE: | 385 | case V4L2_CID_AUDIO_MUTE: |
429 | tea5764_mute(radio, ctrl->value); | 386 | tea5764_mute(radio, ctrl->val); |
430 | return 0; | 387 | return 0; |
431 | } | 388 | } |
432 | return -EINVAL; | 389 | return -EINVAL; |
@@ -465,6 +422,10 @@ static int vidioc_s_audio(struct file *file, void *priv, | |||
465 | return 0; | 422 | return 0; |
466 | } | 423 | } |
467 | 424 | ||
425 | static const struct v4l2_ctrl_ops tea5764_ctrl_ops = { | ||
426 | .s_ctrl = tea5764_s_ctrl, | ||
427 | }; | ||
428 | |||
468 | /* File system interface */ | 429 | /* File system interface */ |
469 | static const struct v4l2_file_operations tea5764_fops = { | 430 | static const struct v4l2_file_operations tea5764_fops = { |
470 | .owner = THIS_MODULE, | 431 | .owner = THIS_MODULE, |
@@ -481,9 +442,6 @@ static const struct v4l2_ioctl_ops tea5764_ioctl_ops = { | |||
481 | .vidioc_s_input = vidioc_s_input, | 442 | .vidioc_s_input = vidioc_s_input, |
482 | .vidioc_g_frequency = vidioc_g_frequency, | 443 | .vidioc_g_frequency = vidioc_g_frequency, |
483 | .vidioc_s_frequency = vidioc_s_frequency, | 444 | .vidioc_s_frequency = vidioc_s_frequency, |
484 | .vidioc_queryctrl = vidioc_queryctrl, | ||
485 | .vidioc_g_ctrl = vidioc_g_ctrl, | ||
486 | .vidioc_s_ctrl = vidioc_s_ctrl, | ||
487 | }; | 445 | }; |
488 | 446 | ||
489 | /* V4L2 interface */ | 447 | /* V4L2 interface */ |
@@ -500,6 +458,7 @@ static int tea5764_i2c_probe(struct i2c_client *client, | |||
500 | { | 458 | { |
501 | struct tea5764_device *radio; | 459 | struct tea5764_device *radio; |
502 | struct v4l2_device *v4l2_dev; | 460 | struct v4l2_device *v4l2_dev; |
461 | struct v4l2_ctrl_handler *hdl; | ||
503 | struct tea5764_regs *r; | 462 | struct tea5764_regs *r; |
504 | int ret; | 463 | int ret; |
505 | 464 | ||
@@ -514,6 +473,18 @@ static int tea5764_i2c_probe(struct i2c_client *client, | |||
514 | v4l2_err(v4l2_dev, "could not register v4l2_device\n"); | 473 | v4l2_err(v4l2_dev, "could not register v4l2_device\n"); |
515 | goto errfr; | 474 | goto errfr; |
516 | } | 475 | } |
476 | |||
477 | hdl = &radio->ctrl_handler; | ||
478 | v4l2_ctrl_handler_init(hdl, 1); | ||
479 | v4l2_ctrl_new_std(hdl, &tea5764_ctrl_ops, | ||
480 | V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1); | ||
481 | v4l2_dev->ctrl_handler = hdl; | ||
482 | if (hdl->error) { | ||
483 | ret = hdl->error; | ||
484 | v4l2_err(v4l2_dev, "Could not register controls\n"); | ||
485 | goto errunreg; | ||
486 | } | ||
487 | |||
517 | mutex_init(&radio->mutex); | 488 | mutex_init(&radio->mutex); |
518 | radio->i2c_client = client; | 489 | radio->i2c_client = client; |
519 | ret = tea5764_i2c_read(radio); | 490 | ret = tea5764_i2c_read(radio); |
@@ -550,6 +521,7 @@ static int tea5764_i2c_probe(struct i2c_client *client, | |||
550 | PINFO("registered."); | 521 | PINFO("registered."); |
551 | return 0; | 522 | return 0; |
552 | errunreg: | 523 | errunreg: |
524 | v4l2_ctrl_handler_free(hdl); | ||
553 | v4l2_device_unregister(v4l2_dev); | 525 | v4l2_device_unregister(v4l2_dev); |
554 | errfr: | 526 | errfr: |
555 | kfree(radio); | 527 | kfree(radio); |
@@ -564,6 +536,7 @@ static int tea5764_i2c_remove(struct i2c_client *client) | |||
564 | if (radio) { | 536 | if (radio) { |
565 | tea5764_power_down(radio); | 537 | tea5764_power_down(radio); |
566 | video_unregister_device(&radio->vdev); | 538 | video_unregister_device(&radio->vdev); |
539 | v4l2_ctrl_handler_free(&radio->ctrl_handler); | ||
567 | v4l2_device_unregister(&radio->v4l2_dev); | 540 | v4l2_device_unregister(&radio->v4l2_dev); |
568 | kfree(radio); | 541 | kfree(radio); |
569 | } | 542 | } |