]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/pvrusb2/pvrusb2-ctrl.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6-omap-h63xx.git] / drivers / media / video / pvrusb2 / pvrusb2-ctrl.c
index d5df9fbeba2ff46b97d6929416984d41fabf0c8a..f569b00201ddb09924e854cf84f4977795fee729 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,12 +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) {
-                               if (val < cptr->info->def.type_int.min_value) {
-                                       break;
-                               }
-                               if (val > cptr->info->def.type_int.max_value) {
-                                       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;
@@ -91,7 +108,9 @@ int pvr2_ctrl_get_max(struct pvr2_ctrl *cptr)
        int ret = 0;
        if (!cptr) return 0;
        LOCK_TAKE(cptr->hdw->big_lock); do {
-               if (cptr->info->type == pvr2_ctl_int) {
+               if (cptr->info->get_max_value) {
+                       cptr->info->get_max_value(cptr,&ret);
+               } else if (cptr->info->type == pvr2_ctl_int) {
                        ret = cptr->info->def.type_int.max_value;
                }
        } while(0); LOCK_GIVE(cptr->hdw->big_lock);
@@ -105,7 +124,9 @@ int pvr2_ctrl_get_min(struct pvr2_ctrl *cptr)
        int ret = 0;
        if (!cptr) return 0;
        LOCK_TAKE(cptr->hdw->big_lock); do {
-               if (cptr->info->type == pvr2_ctl_int) {
+               if (cptr->info->get_min_value) {
+                       cptr->info->get_min_value(cptr,&ret);
+               } else if (cptr->info->type == pvr2_ctl_int) {
                        ret = cptr->info->def.type_int.min_value;
                }
        } while(0); LOCK_GIVE(cptr->hdw->big_lock);
@@ -158,7 +179,7 @@ int pvr2_ctrl_get_mask(struct pvr2_ctrl *cptr)
 /* Retrieve the control's name */
 const char *pvr2_ctrl_get_name(struct pvr2_ctrl *cptr)
 {
-       if (!cptr) return 0;
+       if (!cptr) return NULL;
        return cptr->info->name;
 }
 
@@ -166,7 +187,7 @@ const char *pvr2_ctrl_get_name(struct pvr2_ctrl *cptr)
 /* Retrieve the control's desc */
 const char *pvr2_ctrl_get_desc(struct pvr2_ctrl *cptr)
 {
-       if (!cptr) return 0;
+       if (!cptr) return NULL;
        return cptr->info->desc;
 }
 
@@ -488,17 +509,14 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
 
        LOCK_TAKE(cptr->hdw->big_lock); do {
                if (cptr->info->type == pvr2_ctl_int) {
-                       ret = parse_token(ptr,len,valptr,0,0);
-                       if ((ret >= 0) &&
-                           ((*valptr < cptr->info->def.type_int.min_value) ||
-                            (*valptr > cptr->info->def.type_int.max_value))) {
-                               ret = -ERANGE;
+                       ret = parse_token(ptr,len,valptr,NULL,0);
+                       if (ret >= 0) {
+                               ret = pvr2_ctrl_range_check(cptr,*valptr);
                        }
                        if (maskptr) *maskptr = ~0;
                } else if (cptr->info->type == pvr2_ctl_bool) {
-                       ret = parse_token(
-                               ptr,len,valptr,boolNames,
-                               sizeof(boolNames)/sizeof(boolNames[0]));
+                       ret = parse_token(ptr,len,valptr,boolNames,
+                                         ARRAY_SIZE(boolNames));
                        if (ret == 1) {
                                *valptr = *valptr ? !0 : 0;
                        } else if (ret == 0) {