| .. | .. |
|---|
| 63 | 63 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
|---|
| 64 | 64 | unsigned int val, item; |
|---|
| 65 | 65 | unsigned int reg_val; |
|---|
| 66 | | - int ret; |
|---|
| 67 | 66 | |
|---|
| 68 | | - ret = snd_soc_component_read(component, e->reg, ®_val); |
|---|
| 69 | | - if (ret) |
|---|
| 70 | | - return ret; |
|---|
| 67 | + reg_val = snd_soc_component_read(component, e->reg); |
|---|
| 71 | 68 | val = (reg_val >> e->shift_l) & e->mask; |
|---|
| 72 | 69 | item = snd_soc_enum_val_to_item(e, val); |
|---|
| 73 | 70 | ucontrol->value.enumerated.item[0] = item; |
|---|
| .. | .. |
|---|
| 136 | 133 | int ret; |
|---|
| 137 | 134 | unsigned int val; |
|---|
| 138 | 135 | |
|---|
| 139 | | - ret = snd_soc_component_read(component, reg, &val); |
|---|
| 140 | | - if (ret < 0) |
|---|
| 141 | | - return ret; |
|---|
| 142 | | - |
|---|
| 136 | + val = snd_soc_component_read(component, reg); |
|---|
| 143 | 137 | val = (val >> shift) & mask; |
|---|
| 144 | 138 | |
|---|
| 145 | 139 | if (!sign_bit) { |
|---|
| .. | .. |
|---|
| 323 | 317 | mask = BIT(sign_bit + 1) - 1; |
|---|
| 324 | 318 | |
|---|
| 325 | 319 | val = ucontrol->value.integer.value[0]; |
|---|
| 326 | | - if (mc->platform_max && val > mc->platform_max) |
|---|
| 320 | + if (mc->platform_max && ((int)val + min) > mc->platform_max) |
|---|
| 327 | 321 | return -EINVAL; |
|---|
| 328 | 322 | if (val > max - min) |
|---|
| 329 | 323 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 336 | 330 | val = val << shift; |
|---|
| 337 | 331 | if (snd_soc_volsw_is_stereo(mc)) { |
|---|
| 338 | 332 | val2 = ucontrol->value.integer.value[1]; |
|---|
| 339 | | - if (mc->platform_max && val2 > mc->platform_max) |
|---|
| 333 | + if (mc->platform_max && ((int)val2 + min) > mc->platform_max) |
|---|
| 340 | 334 | return -EINVAL; |
|---|
| 341 | 335 | if (val2 > max - min) |
|---|
| 342 | 336 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 395 | 389 | int min = mc->min; |
|---|
| 396 | 390 | unsigned int mask = (1U << (fls(min + max) - 1)) - 1; |
|---|
| 397 | 391 | unsigned int val; |
|---|
| 398 | | - int ret; |
|---|
| 399 | 392 | |
|---|
| 400 | | - ret = snd_soc_component_read(component, reg, &val); |
|---|
| 401 | | - if (ret < 0) |
|---|
| 402 | | - return ret; |
|---|
| 403 | | - |
|---|
| 393 | + val = snd_soc_component_read(component, reg); |
|---|
| 404 | 394 | ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask; |
|---|
| 405 | 395 | |
|---|
| 406 | 396 | if (snd_soc_volsw_is_stereo(mc)) { |
|---|
| 407 | | - ret = snd_soc_component_read(component, reg2, &val); |
|---|
| 408 | | - if (ret < 0) |
|---|
| 409 | | - return ret; |
|---|
| 410 | | - |
|---|
| 397 | + val = snd_soc_component_read(component, reg2); |
|---|
| 411 | 398 | val = ((val >> rshift) - min) & mask; |
|---|
| 412 | 399 | ucontrol->value.integer.value[1] = val; |
|---|
| 413 | 400 | } |
|---|
| .. | .. |
|---|
| 445 | 432 | val = ucontrol->value.integer.value[0]; |
|---|
| 446 | 433 | if (mc->platform_max && val > mc->platform_max) |
|---|
| 447 | 434 | return -EINVAL; |
|---|
| 448 | | - if (val > max - min) |
|---|
| 435 | + if (val > max) |
|---|
| 449 | 436 | return -EINVAL; |
|---|
| 450 | 437 | if (val < 0) |
|---|
| 451 | 438 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 458 | 445 | return err; |
|---|
| 459 | 446 | |
|---|
| 460 | 447 | if (snd_soc_volsw_is_stereo(mc)) { |
|---|
| 448 | + val2 = ucontrol->value.integer.value[1]; |
|---|
| 449 | + |
|---|
| 450 | + if (mc->platform_max && val2 > mc->platform_max) |
|---|
| 451 | + return -EINVAL; |
|---|
| 452 | + if (val2 > max) |
|---|
| 453 | + return -EINVAL; |
|---|
| 454 | + |
|---|
| 461 | 455 | val_mask = mask << rshift; |
|---|
| 462 | | - val2 = (ucontrol->value.integer.value[1] + min) & mask; |
|---|
| 456 | + val2 = (val2 + min) & mask; |
|---|
| 463 | 457 | val2 = val2 << rshift; |
|---|
| 464 | 458 | |
|---|
| 465 | 459 | err = snd_soc_component_update_bits(component, reg2, val_mask, |
|---|
| .. | .. |
|---|
| 523 | 517 | unsigned int mask = (1 << fls(max)) - 1; |
|---|
| 524 | 518 | unsigned int invert = mc->invert; |
|---|
| 525 | 519 | unsigned int val, val_mask; |
|---|
| 526 | | - int err, ret; |
|---|
| 520 | + int err, ret, tmp; |
|---|
| 521 | + |
|---|
| 522 | + tmp = ucontrol->value.integer.value[0]; |
|---|
| 523 | + if (tmp < 0) |
|---|
| 524 | + return -EINVAL; |
|---|
| 525 | + if (mc->platform_max && tmp > mc->platform_max) |
|---|
| 526 | + return -EINVAL; |
|---|
| 527 | + if (tmp > mc->max - mc->min) |
|---|
| 528 | + return -EINVAL; |
|---|
| 527 | 529 | |
|---|
| 528 | 530 | if (invert) |
|---|
| 529 | 531 | val = (max - ucontrol->value.integer.value[0]) & mask; |
|---|
| .. | .. |
|---|
| 538 | 540 | ret = err; |
|---|
| 539 | 541 | |
|---|
| 540 | 542 | if (snd_soc_volsw_is_stereo(mc)) { |
|---|
| 543 | + tmp = ucontrol->value.integer.value[1]; |
|---|
| 544 | + if (tmp < 0) |
|---|
| 545 | + return -EINVAL; |
|---|
| 546 | + if (mc->platform_max && tmp > mc->platform_max) |
|---|
| 547 | + return -EINVAL; |
|---|
| 548 | + if (tmp > mc->max - mc->min) |
|---|
| 549 | + return -EINVAL; |
|---|
| 550 | + |
|---|
| 541 | 551 | if (invert) |
|---|
| 542 | 552 | val = (max - ucontrol->value.integer.value[1]) & mask; |
|---|
| 543 | 553 | else |
|---|
| .. | .. |
|---|
| 580 | 590 | unsigned int mask = (1 << fls(max)) - 1; |
|---|
| 581 | 591 | unsigned int invert = mc->invert; |
|---|
| 582 | 592 | unsigned int val; |
|---|
| 583 | | - int ret; |
|---|
| 584 | 593 | |
|---|
| 585 | | - ret = snd_soc_component_read(component, reg, &val); |
|---|
| 586 | | - if (ret) |
|---|
| 587 | | - return ret; |
|---|
| 588 | | - |
|---|
| 594 | + val = snd_soc_component_read(component, reg); |
|---|
| 589 | 595 | ucontrol->value.integer.value[0] = (val >> shift) & mask; |
|---|
| 590 | 596 | if (invert) |
|---|
| 591 | 597 | ucontrol->value.integer.value[0] = |
|---|
| .. | .. |
|---|
| 595 | 601 | ucontrol->value.integer.value[0] - min; |
|---|
| 596 | 602 | |
|---|
| 597 | 603 | if (snd_soc_volsw_is_stereo(mc)) { |
|---|
| 598 | | - ret = snd_soc_component_read(component, rreg, &val); |
|---|
| 599 | | - if (ret) |
|---|
| 600 | | - return ret; |
|---|
| 601 | | - |
|---|
| 604 | + val = snd_soc_component_read(component, rreg); |
|---|
| 602 | 605 | ucontrol->value.integer.value[1] = (val >> shift) & mask; |
|---|
| 603 | 606 | if (invert) |
|---|
| 604 | 607 | ucontrol->value.integer.value[1] = |
|---|
| .. | .. |
|---|
| 624 | 627 | int snd_soc_limit_volume(struct snd_soc_card *card, |
|---|
| 625 | 628 | const char *name, int max) |
|---|
| 626 | 629 | { |
|---|
| 627 | | - struct snd_card *snd_card = card->snd_card; |
|---|
| 628 | 630 | struct snd_kcontrol *kctl; |
|---|
| 629 | 631 | struct soc_mixer_control *mc; |
|---|
| 630 | | - int found = 0; |
|---|
| 631 | 632 | int ret = -EINVAL; |
|---|
| 632 | 633 | |
|---|
| 633 | 634 | /* Sanity check for name and max */ |
|---|
| 634 | 635 | if (unlikely(!name || max <= 0)) |
|---|
| 635 | 636 | return -EINVAL; |
|---|
| 636 | 637 | |
|---|
| 637 | | - list_for_each_entry(kctl, &snd_card->controls, list) { |
|---|
| 638 | | - if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { |
|---|
| 639 | | - found = 1; |
|---|
| 640 | | - break; |
|---|
| 641 | | - } |
|---|
| 642 | | - } |
|---|
| 643 | | - if (found) { |
|---|
| 638 | + kctl = snd_soc_card_get_kcontrol(card, name); |
|---|
| 639 | + if (kctl) { |
|---|
| 644 | 640 | mc = (struct soc_mixer_control *)kctl->private_value; |
|---|
| 645 | 641 | if (max <= mc->max) { |
|---|
| 646 | 642 | mc->platform_max = max; |
|---|
| .. | .. |
|---|
| 872 | 868 | long val = 0; |
|---|
| 873 | 869 | unsigned int regval; |
|---|
| 874 | 870 | unsigned int i; |
|---|
| 875 | | - int ret; |
|---|
| 876 | 871 | |
|---|
| 877 | 872 | for (i = 0; i < regcount; i++) { |
|---|
| 878 | | - ret = snd_soc_component_read(component, regbase+i, ®val); |
|---|
| 879 | | - if (ret) |
|---|
| 880 | | - return ret; |
|---|
| 873 | + regval = snd_soc_component_read(component, regbase+i); |
|---|
| 881 | 874 | val |= (regval & regwmask) << (regwshift*(regcount-i-1)); |
|---|
| 882 | 875 | } |
|---|
| 883 | 876 | val &= mask; |
|---|
| .. | .. |
|---|
| 959 | 952 | unsigned int mask = 1 << shift; |
|---|
| 960 | 953 | unsigned int invert = mc->invert != 0; |
|---|
| 961 | 954 | unsigned int val; |
|---|
| 962 | | - int ret; |
|---|
| 963 | 955 | |
|---|
| 964 | | - ret = snd_soc_component_read(component, reg, &val); |
|---|
| 965 | | - if (ret) |
|---|
| 966 | | - return ret; |
|---|
| 967 | | - |
|---|
| 956 | + val = snd_soc_component_read(component, reg); |
|---|
| 968 | 957 | val &= mask; |
|---|
| 969 | 958 | |
|---|
| 970 | 959 | if (shift != 0 && val != 0) |
|---|