aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c101
1 files changed, 16 insertions, 85 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 851733897206..2ddc7a4939d2 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2596,14 +2596,18 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2596{ 2596{
2597 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2597 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2598 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2598 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2599 unsigned int val; 2599 unsigned int val, item;
2600 unsigned int reg_val;
2600 2601
2601 val = snd_soc_read(codec, e->reg); 2602 reg_val = snd_soc_read(codec, e->reg);
2602 ucontrol->value.enumerated.item[0] 2603 val = (reg_val >> e->shift_l) & e->mask;
2603 = (val >> e->shift_l) & e->mask; 2604 item = snd_soc_enum_val_to_item(e, val);
2604 if (e->shift_l != e->shift_r) 2605 ucontrol->value.enumerated.item[0] = item;
2605 ucontrol->value.enumerated.item[1] = 2606 if (e->shift_l != e->shift_r) {
2606 (val >> e->shift_r) & e->mask; 2607 val = (reg_val >> e->shift_l) & e->mask;
2608 item = snd_soc_enum_val_to_item(e, val);
2609 ucontrol->value.enumerated.item[1] = item;
2610 }
2607 2611
2608 return 0; 2612 return 0;
2609} 2613}
@@ -2623,17 +2627,18 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2623{ 2627{
2624 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2628 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2625 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2629 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2630 unsigned int *item = ucontrol->value.enumerated.item;
2626 unsigned int val; 2631 unsigned int val;
2627 unsigned int mask; 2632 unsigned int mask;
2628 2633
2629 if (ucontrol->value.enumerated.item[0] >= e->items) 2634 if (item[0] >= e->items)
2630 return -EINVAL; 2635 return -EINVAL;
2631 val = ucontrol->value.enumerated.item[0] << e->shift_l; 2636 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
2632 mask = e->mask << e->shift_l; 2637 mask = e->mask << e->shift_l;
2633 if (e->shift_l != e->shift_r) { 2638 if (e->shift_l != e->shift_r) {
2634 if (ucontrol->value.enumerated.item[1] >= e->items) 2639 if (item[1] >= e->items)
2635 return -EINVAL; 2640 return -EINVAL;
2636 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2641 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
2637 mask |= e->mask << e->shift_r; 2642 mask |= e->mask << e->shift_r;
2638 } 2643 }
2639 2644
@@ -2642,80 +2647,6 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2642EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2647EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2643 2648
2644/** 2649/**
2645 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2646 * @kcontrol: mixer control
2647 * @ucontrol: control element information
2648 *
2649 * Callback to get the value of a double semi enumerated mixer.
2650 *
2651 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2652 * used for handling bitfield coded enumeration for example.
2653 *
2654 * Returns 0 for success.
2655 */
2656int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2657 struct snd_ctl_elem_value *ucontrol)
2658{
2659 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2660 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2661 unsigned int reg_val, val, mux;
2662
2663 reg_val = snd_soc_read(codec, e->reg);
2664 val = (reg_val >> e->shift_l) & e->mask;
2665 for (mux = 0; mux < e->items; mux++) {
2666 if (val == e->values[mux])
2667 break;
2668 }
2669 ucontrol->value.enumerated.item[0] = mux;
2670 if (e->shift_l != e->shift_r) {
2671 val = (reg_val >> e->shift_r) & e->mask;
2672 for (mux = 0; mux < e->items; mux++) {
2673 if (val == e->values[mux])
2674 break;
2675 }
2676 ucontrol->value.enumerated.item[1] = mux;
2677 }
2678
2679 return 0;
2680}
2681EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2682
2683/**
2684 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2685 * @kcontrol: mixer control
2686 * @ucontrol: control element information
2687 *
2688 * Callback to set the value of a double semi enumerated mixer.
2689 *
2690 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2691 * used for handling bitfield coded enumeration for example.
2692 *
2693 * Returns 0 for success.
2694 */
2695int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2696 struct snd_ctl_elem_value *ucontrol)
2697{
2698 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2699 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2700 unsigned int val;
2701 unsigned int mask;
2702
2703 if (ucontrol->value.enumerated.item[0] >= e->items)
2704 return -EINVAL;
2705 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2706 mask = e->mask << e->shift_l;
2707 if (e->shift_l != e->shift_r) {
2708 if (ucontrol->value.enumerated.item[1] >= e->items)
2709 return -EINVAL;
2710 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2711 mask |= e->mask << e->shift_r;
2712 }
2713
2714 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2715}
2716EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2717
2718/**
2719 * snd_soc_read_signed - Read a codec register and interprete as signed value 2650 * snd_soc_read_signed - Read a codec register and interprete as signed value
2720 * @codec: codec 2651 * @codec: codec
2721 * @reg: Register to read 2652 * @reg: Register to read