diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2013-06-10 03:50:11 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-06-17 08:20:26 -0400 |
commit | 8ff618320ce304cf96d84dcacd606d3b7f82c78d (patch) | |
tree | 9eed37883a98848ce563822f2db61b66564e5232 | |
parent | 2249aa5c97a017be4e3b5bb0e9a3ca2d2ed31b27 (diff) |
[media] saa7706h: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Richard Röjfors <richard.rojfors@pelagicore.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/radio/saa7706h.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/drivers/media/radio/saa7706h.c b/drivers/media/radio/saa7706h.c index d1f30d6762d3..ec805b09c608 100644 --- a/drivers/media/radio/saa7706h.c +++ b/drivers/media/radio/saa7706h.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <media/v4l2-device.h> | 27 | #include <media/v4l2-device.h> |
28 | #include <media/v4l2-ctrls.h> | ||
28 | 29 | ||
29 | #define DRIVER_NAME "saa7706h" | 30 | #define DRIVER_NAME "saa7706h" |
30 | 31 | ||
@@ -126,6 +127,7 @@ | |||
126 | 127 | ||
127 | struct saa7706h_state { | 128 | struct saa7706h_state { |
128 | struct v4l2_subdev sd; | 129 | struct v4l2_subdev sd; |
130 | struct v4l2_ctrl_handler hdl; | ||
129 | unsigned muted; | 131 | unsigned muted; |
130 | }; | 132 | }; |
131 | 133 | ||
@@ -316,42 +318,32 @@ static int saa7706h_mute(struct v4l2_subdev *sd) | |||
316 | return err; | 318 | return err; |
317 | } | 319 | } |
318 | 320 | ||
319 | static int saa7706h_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) | 321 | static int saa7706h_s_ctrl(struct v4l2_ctrl *ctrl) |
320 | { | 322 | { |
321 | switch (qc->id) { | 323 | struct saa7706h_state *state = |
322 | case V4L2_CID_AUDIO_MUTE: | 324 | container_of(ctrl->handler, struct saa7706h_state, hdl); |
323 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); | ||
324 | } | ||
325 | return -EINVAL; | ||
326 | } | ||
327 | |||
328 | static int saa7706h_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | ||
329 | { | ||
330 | struct saa7706h_state *state = to_state(sd); | ||
331 | 325 | ||
332 | switch (ctrl->id) { | 326 | switch (ctrl->id) { |
333 | case V4L2_CID_AUDIO_MUTE: | 327 | case V4L2_CID_AUDIO_MUTE: |
334 | ctrl->value = state->muted; | 328 | if (ctrl->val) |
335 | return 0; | 329 | return saa7706h_mute(&state->sd); |
330 | return saa7706h_unmute(&state->sd); | ||
336 | } | 331 | } |
337 | return -EINVAL; | 332 | return -EINVAL; |
338 | } | 333 | } |
339 | 334 | ||
340 | static int saa7706h_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | 335 | static const struct v4l2_ctrl_ops saa7706h_ctrl_ops = { |
341 | { | 336 | .s_ctrl = saa7706h_s_ctrl, |
342 | switch (ctrl->id) { | 337 | }; |
343 | case V4L2_CID_AUDIO_MUTE: | ||
344 | if (ctrl->value) | ||
345 | return saa7706h_mute(sd); | ||
346 | return saa7706h_unmute(sd); | ||
347 | } | ||
348 | return -EINVAL; | ||
349 | } | ||
350 | 338 | ||
351 | static const struct v4l2_subdev_core_ops saa7706h_core_ops = { | 339 | static const struct v4l2_subdev_core_ops saa7706h_core_ops = { |
352 | .queryctrl = saa7706h_queryctrl, | 340 | .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, |
353 | .g_ctrl = saa7706h_g_ctrl, | 341 | .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, |
354 | .s_ctrl = saa7706h_s_ctrl, | 342 | .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, |
343 | .g_ctrl = v4l2_subdev_g_ctrl, | ||
344 | .s_ctrl = v4l2_subdev_s_ctrl, | ||
345 | .queryctrl = v4l2_subdev_queryctrl, | ||
346 | .querymenu = v4l2_subdev_querymenu, | ||
355 | }; | 347 | }; |
356 | 348 | ||
357 | static const struct v4l2_subdev_ops saa7706h_ops = { | 349 | static const struct v4l2_subdev_ops saa7706h_ops = { |
@@ -383,13 +375,20 @@ static int saa7706h_probe(struct i2c_client *client, | |||
383 | sd = &state->sd; | 375 | sd = &state->sd; |
384 | v4l2_i2c_subdev_init(sd, client, &saa7706h_ops); | 376 | v4l2_i2c_subdev_init(sd, client, &saa7706h_ops); |
385 | 377 | ||
378 | v4l2_ctrl_handler_init(&state->hdl, 4); | ||
379 | v4l2_ctrl_new_std(&state->hdl, &saa7706h_ctrl_ops, | ||
380 | V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1); | ||
381 | sd->ctrl_handler = &state->hdl; | ||
382 | err = state->hdl.error; | ||
383 | if (err) | ||
384 | goto err; | ||
385 | |||
386 | /* check the rom versions */ | 386 | /* check the rom versions */ |
387 | err = saa7706h_get_reg16(sd, SAA7706H_DSP1_ROM_VER); | 387 | err = saa7706h_get_reg16(sd, SAA7706H_DSP1_ROM_VER); |
388 | if (err < 0) | 388 | if (err < 0) |
389 | goto err; | 389 | goto err; |
390 | if (err != SUPPORTED_DSP1_ROM_VER) | 390 | if (err != SUPPORTED_DSP1_ROM_VER) |
391 | v4l2_warn(sd, "Unknown DSP1 ROM code version: 0x%x\n", err); | 391 | v4l2_warn(sd, "Unknown DSP1 ROM code version: 0x%x\n", err); |
392 | |||
393 | state->muted = 1; | 392 | state->muted = 1; |
394 | 393 | ||
395 | /* startup in a muted state */ | 394 | /* startup in a muted state */ |
@@ -401,6 +400,7 @@ static int saa7706h_probe(struct i2c_client *client, | |||
401 | 400 | ||
402 | err: | 401 | err: |
403 | v4l2_device_unregister_subdev(sd); | 402 | v4l2_device_unregister_subdev(sd); |
403 | v4l2_ctrl_handler_free(&state->hdl); | ||
404 | kfree(to_state(sd)); | 404 | kfree(to_state(sd)); |
405 | 405 | ||
406 | printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", err); | 406 | printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", err); |
@@ -411,9 +411,11 @@ err: | |||
411 | static int saa7706h_remove(struct i2c_client *client) | 411 | static int saa7706h_remove(struct i2c_client *client) |
412 | { | 412 | { |
413 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | 413 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
414 | struct saa7706h_state *state = to_state(sd); | ||
414 | 415 | ||
415 | saa7706h_mute(sd); | 416 | saa7706h_mute(sd); |
416 | v4l2_device_unregister_subdev(sd); | 417 | v4l2_device_unregister_subdev(sd); |
418 | v4l2_ctrl_handler_free(&state->hdl); | ||
417 | kfree(to_state(sd)); | 419 | kfree(to_state(sd)); |
418 | return 0; | 420 | return 0; |
419 | } | 421 | } |