V4L/DVB (5050): Pvrusb2: Newer frequency range checking
authorMike Isely <isely@pobox.com>
Thu, 28 Dec 2006 02:28:54 +0000 (23:28 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Wed, 21 Feb 2007 15:34:33 +0000 (13:34 -0200)
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>
drivers/media/video/pvrusb2/pvrusb2-ctrl.c
drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
drivers/media/video/pvrusb2/pvrusb2-hdw.c

index 5c9cf1523e236a0b4e2b2f5752b62c36f8ab575c..f8f4e2f311ab566cca04ef6609d1db01d1acdb17 100644 (file)
 #include <linux/mutex.h>
 
 
+static int pvr2_ctrl_range_check(struct pvr2_ctrl *cptr,int val)
+{
+       if (cptr->info->check_value) {
+               if (!cptr->info->check_value(cptr,val)) return -ERANGE;
+       } else {
+               int lim;
+               lim = cptr->info->def.type_int.min_value;
+               if (cptr->info->get_min_value) {
+                       cptr->info->get_min_value(cptr,&lim);
+               }
+               if (val < lim) return -ERANGE;
+               lim = cptr->info->def.type_int.max_value;
+               if (cptr->info->get_max_value) {
+                       cptr->info->get_max_value(cptr,&lim);
+               }
+               if (val > lim) return -ERANGE;
+       }
+       return 0;
+}
+
+
 /* Set the given control. */
 int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val)
 {
@@ -43,17 +64,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
                        if (cptr->info->type == pvr2_ctl_bitmask) {
                                mask &= cptr->info->def.type_bitmask.valid_bits;
                        } else if (cptr->info->type == pvr2_ctl_int) {
-                               int lim;
-                               lim = cptr->info->def.type_int.min_value;
-                               if (cptr->info->get_min_value) {
-                                       cptr->info->get_min_value(cptr,&lim);
-                               }
-                               if (val < lim) break;
-                               lim = cptr->info->def.type_int.max_value;
-                               if (cptr->info->get_max_value) {
-                                       cptr->info->get_max_value(cptr,&lim);
-                               }
-                               if (val > lim) break;
+                               ret = pvr2_ctrl_range_check(cptr,val);
+                               if (ret < 0) break;
                        } else if (cptr->info->type == pvr2_ctl_enum) {
                                if (val >= cptr->info->def.type_enum.count) {
                                        break;
@@ -499,18 +511,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
                if (cptr->info->type == pvr2_ctl_int) {
                        ret = parse_token(ptr,len,valptr,NULL,0);
                        if (ret >= 0) {
-                               int min, max;
-                               min = cptr->info->def.type_int.min_value;
-                               if (cptr->info->get_min_value) {
-                                       cptr->info->get_min_value(cptr,&min);
-                               }
-                               max = cptr->info->def.type_int.max_value;
-                               if (cptr->info->get_max_value) {
-                                       cptr->info->get_max_value(cptr,&max);
-                               }
-                               if ((*valptr < min) || (*valptr > max)) {
-                                       ret = -ERANGE;
-                               }
+                               ret = pvr2_ctrl_range_check(cptr,*valptr);
                        }
                        if (maskptr) *maskptr = ~0;
                } else if (cptr->info->type == pvr2_ctl_bool) {
index 746d174d0b0d4b2cb7381c1c43474fac108774a8..da29ae2fb05d93c6efd6a087383348e55e440f6a 100644 (file)
@@ -60,6 +60,7 @@ struct pvr2_decoder;
 
 typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
 typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
+typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
 typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
 typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
 typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
@@ -83,6 +84,7 @@ struct pvr2_ctl_info {
        pvr2_ctlf_get_value get_min_value;  /* Get minimum allowed value */
        pvr2_ctlf_get_value get_max_value;  /* Get maximum allowed value */
        pvr2_ctlf_set_value set_value;      /* Set its value */
+       pvr2_ctlf_check_value check_value;  /* Check that value is valid */
        pvr2_ctlf_val_to_sym val_to_sym;    /* Custom convert value->symbol */
        pvr2_ctlf_sym_to_val sym_to_val;    /* Custom convert symbol->value */
        pvr2_ctlf_is_dirty is_dirty;        /* Return true if dirty */
index fe290f2f4e140330908fe65fa7153786b21a4720..04e746932217c8750f415e35425af9b343342031 100644 (file)
@@ -381,6 +381,15 @@ static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp)
        return 0;
 }
 
+static int ctrl_freq_check(struct pvr2_ctrl *cptr,int v)
+{
+       if (cptr->hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+               return ((v >= RADIO_MIN_FREQ) && (v <= RADIO_MAX_FREQ));
+       } else {
+               return ((v >= TV_MIN_FREQ) && (v <= TV_MAX_FREQ));
+       }
+}
+
 static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp)
 {
        /* Actual maximum depends on radio/tv mode */
@@ -788,6 +797,7 @@ static const struct pvr2_ctl_info control_defs[] = {
                DEFINT(TV_MIN_FREQ,TV_MAX_FREQ),
                /* Hook in check for input value (tv/radio) and adjust
                   max/min values accordingly */
+               .check_value = ctrl_freq_check,
                .get_max_value = ctrl_freq_max_get,
                .get_min_value = ctrl_freq_min_get,
        },{