diff options
author | Mike Isely <isely@pobox.com> | 2006-12-27 21:28:54 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-02-21 10:34:33 -0500 |
commit | 5549f54f46c2375761f42cd2741364316e3b2a13 (patch) | |
tree | bd4d19a7ba79824c4eb0d9c4f27c07b5a4acf82c | |
parent | 2083230084cee50580ee730cd26669704f7939b9 (diff) |
V4L/DVB (5050): Pvrusb2: Newer frequency range checking
Implement new method for doing integer range checking, so that we can
more intelligently range-check radio and tv ranges at once.
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-ctrl.c | 47 | ||||
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h | 2 | ||||
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-hdw.c | 10 |
3 files changed, 36 insertions, 23 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c index 5c9cf1523e23..f8f4e2f311ab 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c +++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c | |||
@@ -26,6 +26,27 @@ | |||
26 | #include <linux/mutex.h> | 26 | #include <linux/mutex.h> |
27 | 27 | ||
28 | 28 | ||
29 | static int pvr2_ctrl_range_check(struct pvr2_ctrl *cptr,int val) | ||
30 | { | ||
31 | if (cptr->info->check_value) { | ||
32 | if (!cptr->info->check_value(cptr,val)) return -ERANGE; | ||
33 | } else { | ||
34 | int lim; | ||
35 | lim = cptr->info->def.type_int.min_value; | ||
36 | if (cptr->info->get_min_value) { | ||
37 | cptr->info->get_min_value(cptr,&lim); | ||
38 | } | ||
39 | if (val < lim) return -ERANGE; | ||
40 | lim = cptr->info->def.type_int.max_value; | ||
41 | if (cptr->info->get_max_value) { | ||
42 | cptr->info->get_max_value(cptr,&lim); | ||
43 | } | ||
44 | if (val > lim) return -ERANGE; | ||
45 | } | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | |||
29 | /* Set the given control. */ | 50 | /* Set the given control. */ |
30 | int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val) | 51 | int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val) |
31 | { | 52 | { |
@@ -43,17 +64,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val) | |||
43 | if (cptr->info->type == pvr2_ctl_bitmask) { | 64 | if (cptr->info->type == pvr2_ctl_bitmask) { |
44 | mask &= cptr->info->def.type_bitmask.valid_bits; | 65 | mask &= cptr->info->def.type_bitmask.valid_bits; |
45 | } else if (cptr->info->type == pvr2_ctl_int) { | 66 | } else if (cptr->info->type == pvr2_ctl_int) { |
46 | int lim; | 67 | ret = pvr2_ctrl_range_check(cptr,val); |
47 | lim = cptr->info->def.type_int.min_value; | 68 | if (ret < 0) break; |
48 | if (cptr->info->get_min_value) { | ||
49 | cptr->info->get_min_value(cptr,&lim); | ||
50 | } | ||
51 | if (val < lim) break; | ||
52 | lim = cptr->info->def.type_int.max_value; | ||
53 | if (cptr->info->get_max_value) { | ||
54 | cptr->info->get_max_value(cptr,&lim); | ||
55 | } | ||
56 | if (val > lim) break; | ||
57 | } else if (cptr->info->type == pvr2_ctl_enum) { | 69 | } else if (cptr->info->type == pvr2_ctl_enum) { |
58 | if (val >= cptr->info->def.type_enum.count) { | 70 | if (val >= cptr->info->def.type_enum.count) { |
59 | break; | 71 | break; |
@@ -499,18 +511,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr, | |||
499 | if (cptr->info->type == pvr2_ctl_int) { | 511 | if (cptr->info->type == pvr2_ctl_int) { |
500 | ret = parse_token(ptr,len,valptr,NULL,0); | 512 | ret = parse_token(ptr,len,valptr,NULL,0); |
501 | if (ret >= 0) { | 513 | if (ret >= 0) { |
502 | int min, max; | 514 | ret = pvr2_ctrl_range_check(cptr,*valptr); |
503 | min = cptr->info->def.type_int.min_value; | ||
504 | if (cptr->info->get_min_value) { | ||
505 | cptr->info->get_min_value(cptr,&min); | ||
506 | } | ||
507 | max = cptr->info->def.type_int.max_value; | ||
508 | if (cptr->info->get_max_value) { | ||
509 | cptr->info->get_max_value(cptr,&max); | ||
510 | } | ||
511 | if ((*valptr < min) || (*valptr > max)) { | ||
512 | ret = -ERANGE; | ||
513 | } | ||
514 | } | 515 | } |
515 | if (maskptr) *maskptr = ~0; | 516 | if (maskptr) *maskptr = ~0; |
516 | } else if (cptr->info->type == pvr2_ctl_bool) { | 517 | } else if (cptr->info->type == pvr2_ctl_bool) { |
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h index 746d174d0b0d..da29ae2fb05d 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h | |||
@@ -60,6 +60,7 @@ struct pvr2_decoder; | |||
60 | 60 | ||
61 | typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); | 61 | typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); |
62 | typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); | 62 | typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); |
63 | typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int); | ||
63 | typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *); | 64 | typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *); |
64 | typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val); | 65 | typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val); |
65 | typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val, | 66 | typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val, |
@@ -83,6 +84,7 @@ struct pvr2_ctl_info { | |||
83 | pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */ | 84 | pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */ |
84 | pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */ | 85 | pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */ |
85 | pvr2_ctlf_set_value set_value; /* Set its value */ | 86 | pvr2_ctlf_set_value set_value; /* Set its value */ |
87 | pvr2_ctlf_check_value check_value; /* Check that value is valid */ | ||
86 | pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */ | 88 | pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */ |
87 | pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */ | 89 | pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */ |
88 | pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */ | 90 | pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */ |
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c index fe290f2f4e14..04e746932217 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c | |||
@@ -381,6 +381,15 @@ static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp) | |||
381 | return 0; | 381 | return 0; |
382 | } | 382 | } |
383 | 383 | ||
384 | static int ctrl_freq_check(struct pvr2_ctrl *cptr,int v) | ||
385 | { | ||
386 | if (cptr->hdw->input_val == PVR2_CVAL_INPUT_RADIO) { | ||
387 | return ((v >= RADIO_MIN_FREQ) && (v <= RADIO_MAX_FREQ)); | ||
388 | } else { | ||
389 | return ((v >= TV_MIN_FREQ) && (v <= TV_MAX_FREQ)); | ||
390 | } | ||
391 | } | ||
392 | |||
384 | static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp) | 393 | static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp) |
385 | { | 394 | { |
386 | /* Actual maximum depends on radio/tv mode */ | 395 | /* Actual maximum depends on radio/tv mode */ |
@@ -788,6 +797,7 @@ static const struct pvr2_ctl_info control_defs[] = { | |||
788 | DEFINT(TV_MIN_FREQ,TV_MAX_FREQ), | 797 | DEFINT(TV_MIN_FREQ,TV_MAX_FREQ), |
789 | /* Hook in check for input value (tv/radio) and adjust | 798 | /* Hook in check for input value (tv/radio) and adjust |
790 | max/min values accordingly */ | 799 | max/min values accordingly */ |
800 | .check_value = ctrl_freq_check, | ||
791 | .get_max_value = ctrl_freq_max_get, | 801 | .get_max_value = ctrl_freq_max_get, |
792 | .get_min_value = ctrl_freq_min_get, | 802 | .get_min_value = ctrl_freq_min_get, |
793 | },{ | 803 | },{ |