diff options
author | Mike Isely <isely@pobox.com> | 2006-06-25 19:04:40 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-26 23:17:27 -0400 |
commit | 332139635a8c0431cc2eb67adf1e983eb96728e3 (patch) | |
tree | e7646bc367486fd1b52bd80bc789fe26307ed9fe /drivers/media/video/pvrusb2/pvrusb2-ctrl.c | |
parent | 077203a7d464f6ea7c94b4f3ea4b5bd246285fcd (diff) |
V4L/DVB (4239): Handle boolean controls in pvrusb2
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-ctrl.c')
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-ctrl.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c index 3577d5bfa007..d644afec5a5c 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c +++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c | |||
@@ -53,6 +53,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val) | |||
53 | if (val >= cptr->info->def.type_enum.count) { | 53 | if (val >= cptr->info->def.type_enum.count) { |
54 | break; | 54 | break; |
55 | } | 55 | } |
56 | } else if (cptr->info->type != pvr2_ctl_bool) { | ||
57 | break; | ||
56 | } | 58 | } |
57 | ret = cptr->info->set_value(cptr,mask,val); | 59 | ret = cptr->info->set_value(cptr,mask,val); |
58 | } else { | 60 | } else { |
@@ -308,6 +310,14 @@ static unsigned int gen_bitmask_string(int msk,int val,int msk_only, | |||
308 | } | 310 | } |
309 | 311 | ||
310 | 312 | ||
313 | static const char *boolNames[] = { | ||
314 | "false", | ||
315 | "true", | ||
316 | "no", | ||
317 | "yes", | ||
318 | }; | ||
319 | |||
320 | |||
311 | static int parse_token(const char *ptr,unsigned int len, | 321 | static int parse_token(const char *ptr,unsigned int len, |
312 | int *valptr, | 322 | int *valptr, |
313 | const char **names,unsigned int namecnt) | 323 | const char **names,unsigned int namecnt) |
@@ -338,7 +348,7 @@ static int parse_token(const char *ptr,unsigned int len, | |||
338 | *valptr = simple_strtol(buf,&p2,0); | 348 | *valptr = simple_strtol(buf,&p2,0); |
339 | if (negfl) *valptr = -(*valptr); | 349 | if (negfl) *valptr = -(*valptr); |
340 | if (*p2) return -EINVAL; | 350 | if (*p2) return -EINVAL; |
341 | return 0; | 351 | return 1; |
342 | } | 352 | } |
343 | 353 | ||
344 | 354 | ||
@@ -453,21 +463,31 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr, | |||
453 | LOCK_TAKE(cptr->hdw->big_lock); do { | 463 | LOCK_TAKE(cptr->hdw->big_lock); do { |
454 | if (cptr->info->type == pvr2_ctl_int) { | 464 | if (cptr->info->type == pvr2_ctl_int) { |
455 | ret = parse_token(ptr,len,valptr,0,0); | 465 | ret = parse_token(ptr,len,valptr,0,0); |
456 | if ((ret == 0) && | 466 | if ((ret >= 0) && |
457 | ((*valptr < cptr->info->def.type_int.min_value) || | 467 | ((*valptr < cptr->info->def.type_int.min_value) || |
458 | (*valptr > cptr->info->def.type_int.max_value))) { | 468 | (*valptr > cptr->info->def.type_int.max_value))) { |
459 | ret = -EINVAL; | 469 | ret = -ERANGE; |
460 | } | 470 | } |
461 | if (maskptr) *maskptr = ~0; | 471 | if (maskptr) *maskptr = ~0; |
472 | } else if (cptr->info->type == pvr2_ctl_bool) { | ||
473 | ret = parse_token( | ||
474 | ptr,len,valptr,boolNames, | ||
475 | sizeof(boolNames)/sizeof(boolNames[0])); | ||
476 | if (ret == 1) { | ||
477 | *valptr = *valptr ? !0 : 0; | ||
478 | } else if (ret == 0) { | ||
479 | *valptr = (*valptr & 1) ? !0 : 0; | ||
480 | } | ||
481 | if (maskptr) *maskptr = 1; | ||
462 | } else if (cptr->info->type == pvr2_ctl_enum) { | 482 | } else if (cptr->info->type == pvr2_ctl_enum) { |
463 | ret = parse_token( | 483 | ret = parse_token( |
464 | ptr,len,valptr, | 484 | ptr,len,valptr, |
465 | cptr->info->def.type_enum.value_names, | 485 | cptr->info->def.type_enum.value_names, |
466 | cptr->info->def.type_enum.count); | 486 | cptr->info->def.type_enum.count); |
467 | if ((ret == 0) && | 487 | if ((ret >= 0) && |
468 | ((*valptr < 0) || | 488 | ((*valptr < 0) || |
469 | (*valptr >= cptr->info->def.type_enum.count))) { | 489 | (*valptr >= cptr->info->def.type_enum.count))) { |
470 | ret = -EINVAL; | 490 | ret = -ERANGE; |
471 | } | 491 | } |
472 | if (maskptr) *maskptr = ~0; | 492 | if (maskptr) *maskptr = ~0; |
473 | } else if (cptr->info->type == pvr2_ctl_bitmask) { | 493 | } else if (cptr->info->type == pvr2_ctl_bitmask) { |
@@ -493,6 +513,9 @@ int pvr2_ctrl_value_to_sym_internal(struct pvr2_ctrl *cptr, | |||
493 | if (cptr->info->type == pvr2_ctl_int) { | 513 | if (cptr->info->type == pvr2_ctl_int) { |
494 | *len = scnprintf(buf,maxlen,"%d",val); | 514 | *len = scnprintf(buf,maxlen,"%d",val); |
495 | ret = 0; | 515 | ret = 0; |
516 | } else if (cptr->info->type == pvr2_ctl_bool) { | ||
517 | *len = scnprintf(buf,maxlen,"%s",val ? "true" : "false"); | ||
518 | ret = 0; | ||
496 | } else if (cptr->info->type == pvr2_ctl_enum) { | 519 | } else if (cptr->info->type == pvr2_ctl_enum) { |
497 | const char **names; | 520 | const char **names; |
498 | names = cptr->info->def.type_enum.value_names; | 521 | names = cptr->info->def.type_enum.value_names; |