23 #include <linux/errno.h>
24 #include <linux/string.h>
28 static int pvr2_ctrl_range_check(
struct pvr2_ctrl *cptr,
int val)
30 if (cptr->
info->check_value) {
31 if (!cptr->
info->check_value(cptr,val))
return -
ERANGE;
33 if (val < 0)
return -
ERANGE;
34 if (val >= cptr->
info->def.type_enum.count)
return -
ERANGE;
37 lim = cptr->
info->def.type_int.min_value;
38 if (cptr->
info->get_min_value) {
39 cptr->
info->get_min_value(cptr,&lim);
41 if (val < lim)
return -
ERANGE;
42 lim = cptr->
info->def.type_int.max_value;
43 if (cptr->
info->get_max_value) {
44 cptr->
info->get_max_value(cptr,&lim);
46 if (val > lim)
return -
ERANGE;
65 if (cptr->
info->set_value) {
67 mask &= cptr->
info->def.type_bitmask.valid_bits;
70 ret = pvr2_ctrl_range_check(cptr,val);
75 ret = cptr->
info->set_value(cptr,mask,val);
90 ret = cptr->
info->get_value(cptr,valptr);
100 return cptr->
info->type;
110 if (cptr->
info->get_max_value) {
111 cptr->
info->get_max_value(cptr,&ret);
113 ret = cptr->
info->def.type_int.max_value;
126 if (cptr->
info->get_min_value) {
127 cptr->
info->get_min_value(cptr,&ret);
129 ret = cptr->
info->def.type_int.min_value;
140 if (!cptr)
return -
EINVAL;
142 if (cptr->
info->get_def_value) {
143 ret = cptr->
info->get_def_value(cptr, valptr);
145 *valptr = cptr->
info->default_value;
159 ret = cptr->
info->def.type_enum.count;
173 ret = cptr->
info->def.type_bitmask.valid_bits;
183 if (!cptr)
return NULL;
184 return cptr->
info->name;
191 if (!cptr)
return NULL;
192 return cptr->
info->desc;
198 char *bptr,
unsigned int bmax,
206 const char *
const *names;
207 names = cptr->
info->def.type_enum.value_names;
208 if (pvr2_ctrl_range_check(cptr,val) == 0) {
222 names = cptr->
info->def.type_bitmask.bit_names;
223 val &= cptr->
info->def.type_bitmask.valid_bits;
224 for (idx = 0, msk = 1;
val; idx++, msk <<= 1) {
242 return cptr->
info->v4l_id;
248 unsigned int flags = 0;
250 if (cptr->
info->get_v4lflags) {
251 flags = cptr->
info->get_v4lflags(cptr);
254 if (cptr->
info->set_value) {
268 return cptr->
info->set_value !=
NULL;
276 if (!cptr->
info->val_to_sym)
return 0;
277 if (!cptr->
info->sym_to_val)
return 0;
285 char *
buf,
unsigned int maxlen,
288 if (!cptr)
return -
EINVAL;
290 return cptr->
info->val_to_sym(cptr,mask,val,buf,maxlen,len);
296 const char *
buf,
unsigned int len,
297 int *maskptr,
int *valptr)
299 if (!cptr)
return -
EINVAL;
301 return cptr->
info->sym_to_val(cptr,buf,len,maskptr,valptr);
305 static unsigned int gen_bitmask_string(
int msk,
int val,
int msk_only,
307 char *
ptr,
unsigned int len)
318 for (idx = 0, sm = 1;
msk; idx++, sm <<= 1) {
326 ((val & sm) ?
"+" :
"-")),
342 }
else if (um & val) {
348 }
else if (um & ~val) {
360 static const char *boolNames[] = {
368 static int parse_token(
const char *ptr,
unsigned int len,
370 const char *
const *names,
unsigned int namecnt)
378 if (!names) namecnt = 0;
379 for (idx = 0; idx < namecnt; idx++) {
380 if (!names[idx])
continue;
381 slen =
strlen(names[idx]);
382 if (slen != len)
continue;
383 if (
memcmp(names[idx],ptr,slen))
continue;
388 if ((*ptr ==
'-') || (*ptr ==
'+')) {
389 negfl = (*ptr ==
'-');
392 if (len >=
sizeof(buf))
return -
EINVAL;
396 if (negfl) *valptr = -(*valptr);
402 static int parse_mtoken(
const char *ptr,
unsigned int len,
404 const char **names,
int valid_bits)
412 for (idx = 0, msk = 1; valid_bits; idx++, msk <<= 1) {
413 if (!(msk & valid_bits))
continue;
415 if (!names[idx])
continue;
416 slen =
strlen(names[idx]);
417 if (slen != len)
continue;
418 if (
memcmp(names[idx],ptr,slen))
continue;
422 if (len >=
sizeof(buf))
return -
EINVAL;
431 static int parse_tlist(
const char *ptr,
unsigned int len,
432 int *maskptr,
int *valptr,
433 const char **names,
int valid_bits)
442 while ((cnt < len) &&
444 (ptr[cnt] >= 127))) cnt++;
448 if ((*ptr ==
'-') || (*ptr ==
'+')) {
449 mode = (*ptr ==
'-') ? -1 : 1;
455 if (ptr[cnt] <= 32)
break;
456 if (ptr[cnt] >= 127)
break;
460 if (parse_mtoken(ptr,cnt,&kv,names,valid_bits)) {
491 const char *ptr,
unsigned int len,
492 int *maskptr,
int *valptr)
501 while ((cnt < len) && ((ptr[cnt] <= 32) || (ptr[cnt] >= 127))) cnt++;
504 while ((cnt < len) && ((ptr[len-(cnt+1)] <= 32) ||
505 (ptr[len-(cnt+1)] >= 127))) cnt++;
512 ret = parse_token(ptr,len,valptr,
NULL,0);
514 ret = pvr2_ctrl_range_check(cptr,*valptr);
518 ret = parse_token(ptr,len,valptr,boolNames,
521 *valptr = *valptr ? !0 : 0;
522 }
else if (ret == 0) {
523 *valptr = (*valptr & 1) ? !0 : 0;
529 cptr->
info->def.type_enum.value_names,
530 cptr->
info->def.type_enum.count);
532 ret = pvr2_ctrl_range_check(cptr,*valptr);
537 ptr,len,maskptr,valptr,
538 cptr->
info->def.type_bitmask.bit_names,
539 cptr->
info->def.type_bitmask.valid_bits);
549 char *buf,
unsigned int maxlen,
559 *len =
scnprintf(buf,maxlen,
"%s",val ?
"true" :
"false");
562 const char *
const *names;
563 names = cptr->
info->def.type_enum.value_names;
565 (val < cptr->
info->def.type_enum.count)) {
576 *len = gen_bitmask_string(
577 val & mask & cptr->
info->def.type_bitmask.valid_bits,
579 cptr->
info->def.type_bitmask.bit_names,
589 char *buf,
unsigned int maxlen,