diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-07-29 11:13:57 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-07-29 13:40:59 -0400 |
commit | eee5d7f99ae95059e1a3d1cfa2dea3ed8dbd94ac (patch) | |
tree | 438cc363a91ee9ddb6ca0584f30e80e476323ac3 | |
parent | 95dd5cd6e16d86786f7dc9da404ae477403d8f83 (diff) |
ASoC: dapm: Add a helper to get the CODEC for DAPM kcontrol
We use the same 3 lines to get the CODEC for a kcontrol in a quite a few places.
This patch puts them into a common helper function. Having this encapsulated in
a helper function will also make it more easier to eventually change the data
layout of the kcontrol's private data.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | include/sound/soc-dapm.h | 2 | ||||
-rw-r--r-- | sound/soc/codecs/tlv320aic3x.c | 7 | ||||
-rw-r--r-- | sound/soc/codecs/twl6040.c | 4 | ||||
-rw-r--r-- | sound/soc/codecs/wm8903.c | 4 | ||||
-rw-r--r-- | sound/soc/codecs/wm8994.c | 4 | ||||
-rw-r--r-- | sound/soc/codecs/wm8995.c | 5 | ||||
-rw-r--r-- | sound/soc/codecs/wm_hubs.c | 8 | ||||
-rw-r--r-- | sound/soc/soc-dapm.c | 40 |
8 files changed, 34 insertions, 40 deletions
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 3397292d94c8..ebfae8f3fda7 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h | |||
@@ -427,6 +427,8 @@ void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm); | |||
427 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, | 427 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, |
428 | struct snd_soc_dapm_widget_list **list); | 428 | struct snd_soc_dapm_widget_list **list); |
429 | 429 | ||
430 | struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol); | ||
431 | |||
430 | /* dapm widget types */ | 432 | /* dapm widget types */ |
431 | enum snd_soc_dapm_type { | 433 | enum snd_soc_dapm_type { |
432 | snd_soc_dapm_input = 0, /* input pin */ | 434 | snd_soc_dapm_input = 0, /* input pin */ |
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index 1325c0c0df50..fec0db04262d 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c | |||
@@ -138,8 +138,7 @@ static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = { | |||
138 | static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol, | 138 | static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol, |
139 | struct snd_ctl_elem_value *ucontrol) | 139 | struct snd_ctl_elem_value *ucontrol) |
140 | { | 140 | { |
141 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 141 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
142 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
143 | struct soc_mixer_control *mc = | 142 | struct soc_mixer_control *mc = |
144 | (struct soc_mixer_control *)kcontrol->private_value; | 143 | (struct soc_mixer_control *)kcontrol->private_value; |
145 | unsigned int reg = mc->reg; | 144 | unsigned int reg = mc->reg; |
@@ -165,14 +164,14 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol, | |||
165 | mask <<= shift; | 164 | mask <<= shift; |
166 | val <<= shift; | 165 | val <<= shift; |
167 | 166 | ||
168 | change = snd_soc_test_bits(widget->codec, val, mask, reg); | 167 | change = snd_soc_test_bits(codec, val, mask, reg); |
169 | if (change) { | 168 | if (change) { |
170 | update.kcontrol = kcontrol; | 169 | update.kcontrol = kcontrol; |
171 | update.reg = reg; | 170 | update.reg = reg; |
172 | update.mask = mask; | 171 | update.mask = mask; |
173 | update.val = val; | 172 | update.val = val; |
174 | 173 | ||
175 | snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, connect, | 174 | snd_soc_dapm_mixer_update_power(&codec->dapm, kcontrol, connect, |
176 | &update); | 175 | &update); |
177 | } | 176 | } |
178 | 177 | ||
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c index 44621ddc332d..d6c5bf14179a 100644 --- a/sound/soc/codecs/twl6040.c +++ b/sound/soc/codecs/twl6040.c | |||
@@ -437,9 +437,7 @@ static irqreturn_t twl6040_audio_handler(int irq, void *data) | |||
437 | static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, | 437 | static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, |
438 | struct snd_ctl_elem_value *ucontrol) | 438 | struct snd_ctl_elem_value *ucontrol) |
439 | { | 439 | { |
440 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 440 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
441 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
442 | struct snd_soc_codec *codec = widget->codec; | ||
443 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | 441 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
444 | unsigned int val; | 442 | unsigned int val; |
445 | 443 | ||
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index fa24cedee687..eebcb1da3b7b 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c | |||
@@ -364,9 +364,7 @@ static void wm8903_seq_notifier(struct snd_soc_dapm_context *dapm, | |||
364 | static int wm8903_class_w_put(struct snd_kcontrol *kcontrol, | 364 | static int wm8903_class_w_put(struct snd_kcontrol *kcontrol, |
365 | struct snd_ctl_elem_value *ucontrol) | 365 | struct snd_ctl_elem_value *ucontrol) |
366 | { | 366 | { |
367 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 367 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
368 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
369 | struct snd_soc_codec *codec = widget->codec; | ||
370 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); | 368 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); |
371 | u16 reg; | 369 | u16 reg; |
372 | int ret; | 370 | int ret; |
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c index ba832b77c543..eee2a01f2691 100644 --- a/sound/soc/codecs/wm8994.c +++ b/sound/soc/codecs/wm8994.c | |||
@@ -1437,9 +1437,7 @@ SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING, | |||
1437 | static int wm8994_put_class_w(struct snd_kcontrol *kcontrol, | 1437 | static int wm8994_put_class_w(struct snd_kcontrol *kcontrol, |
1438 | struct snd_ctl_elem_value *ucontrol) | 1438 | struct snd_ctl_elem_value *ucontrol) |
1439 | { | 1439 | { |
1440 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 1440 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
1441 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; | ||
1442 | struct snd_soc_codec *codec = w->codec; | ||
1443 | int ret; | 1441 | int ret; |
1444 | 1442 | ||
1445 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); | 1443 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); |
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c index 90a65c427541..da2899e6c401 100644 --- a/sound/soc/codecs/wm8995.c +++ b/sound/soc/codecs/wm8995.c | |||
@@ -549,12 +549,9 @@ static int check_clk_sys(struct snd_soc_dapm_widget *source, | |||
549 | static int wm8995_put_class_w(struct snd_kcontrol *kcontrol, | 549 | static int wm8995_put_class_w(struct snd_kcontrol *kcontrol, |
550 | struct snd_ctl_elem_value *ucontrol) | 550 | struct snd_ctl_elem_value *ucontrol) |
551 | { | 551 | { |
552 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 552 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
553 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; | ||
554 | struct snd_soc_codec *codec; | ||
555 | int ret; | 553 | int ret; |
556 | 554 | ||
557 | codec = w->codec; | ||
558 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); | 555 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); |
559 | wm8995_update_class_w(codec); | 556 | wm8995_update_class_w(codec); |
560 | return ret; | 557 | return ret; |
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c index 2d9e099415a5..8b50e5958de5 100644 --- a/sound/soc/codecs/wm_hubs.c +++ b/sound/soc/codecs/wm_hubs.c | |||
@@ -699,9 +699,7 @@ EXPORT_SYMBOL_GPL(wm_hubs_update_class_w); | |||
699 | static int class_w_put_volsw(struct snd_kcontrol *kcontrol, | 699 | static int class_w_put_volsw(struct snd_kcontrol *kcontrol, |
700 | struct snd_ctl_elem_value *ucontrol) | 700 | struct snd_ctl_elem_value *ucontrol) |
701 | { | 701 | { |
702 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 702 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
703 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
704 | struct snd_soc_codec *codec = widget->codec; | ||
705 | int ret; | 703 | int ret; |
706 | 704 | ||
707 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); | 705 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); |
@@ -721,9 +719,7 @@ static int class_w_put_volsw(struct snd_kcontrol *kcontrol, | |||
721 | static int class_w_put_double(struct snd_kcontrol *kcontrol, | 719 | static int class_w_put_double(struct snd_kcontrol *kcontrol, |
722 | struct snd_ctl_elem_value *ucontrol) | 720 | struct snd_ctl_elem_value *ucontrol) |
723 | { | 721 | { |
724 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 722 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
725 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
726 | struct snd_soc_codec *codec = widget->codec; | ||
727 | int ret; | 723 | int ret; |
728 | 724 | ||
729 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); | 725 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 5db8df2f8866..b18ac5b1cc2e 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -174,6 +174,17 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget( | |||
174 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); | 174 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
175 | } | 175 | } |
176 | 176 | ||
177 | /** | ||
178 | * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol | ||
179 | * @kcontrol: The kcontrol | ||
180 | */ | ||
181 | struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol) | ||
182 | { | ||
183 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | ||
184 | return wlist->widgets[0]->codec; | ||
185 | } | ||
186 | EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_codec); | ||
187 | |||
177 | static void dapm_reset(struct snd_soc_card *card) | 188 | static void dapm_reset(struct snd_soc_card *card) |
178 | { | 189 | { |
179 | struct snd_soc_dapm_widget *w; | 190 | struct snd_soc_dapm_widget *w; |
@@ -2617,8 +2628,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); | |||
2617 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, | 2628 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
2618 | struct snd_ctl_elem_value *ucontrol) | 2629 | struct snd_ctl_elem_value *ucontrol) |
2619 | { | 2630 | { |
2620 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2631 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
2621 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
2622 | struct soc_mixer_control *mc = | 2632 | struct soc_mixer_control *mc = |
2623 | (struct soc_mixer_control *)kcontrol->private_value; | 2633 | (struct soc_mixer_control *)kcontrol->private_value; |
2624 | unsigned int reg = mc->reg; | 2634 | unsigned int reg = mc->reg; |
@@ -2628,12 +2638,12 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, | |||
2628 | unsigned int invert = mc->invert; | 2638 | unsigned int invert = mc->invert; |
2629 | 2639 | ||
2630 | if (snd_soc_volsw_is_stereo(mc)) | 2640 | if (snd_soc_volsw_is_stereo(mc)) |
2631 | dev_warn(widget->dapm->dev, | 2641 | dev_warn(codec->dapm.dev, |
2632 | "ASoC: Control '%s' is stereo, which is not supported\n", | 2642 | "ASoC: Control '%s' is stereo, which is not supported\n", |
2633 | kcontrol->id.name); | 2643 | kcontrol->id.name); |
2634 | 2644 | ||
2635 | ucontrol->value.integer.value[0] = | 2645 | ucontrol->value.integer.value[0] = |
2636 | (snd_soc_read(widget->codec, reg) >> shift) & mask; | 2646 | (snd_soc_read(codec, reg) >> shift) & mask; |
2637 | if (invert) | 2647 | if (invert) |
2638 | ucontrol->value.integer.value[0] = | 2648 | ucontrol->value.integer.value[0] = |
2639 | max - ucontrol->value.integer.value[0]; | 2649 | max - ucontrol->value.integer.value[0]; |
@@ -2654,9 +2664,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); | |||
2654 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, | 2664 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
2655 | struct snd_ctl_elem_value *ucontrol) | 2665 | struct snd_ctl_elem_value *ucontrol) |
2656 | { | 2666 | { |
2657 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2667 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
2658 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
2659 | struct snd_soc_codec *codec = widget->codec; | ||
2660 | struct snd_soc_card *card = codec->card; | 2668 | struct snd_soc_card *card = codec->card; |
2661 | struct soc_mixer_control *mc = | 2669 | struct soc_mixer_control *mc = |
2662 | (struct soc_mixer_control *)kcontrol->private_value; | 2670 | (struct soc_mixer_control *)kcontrol->private_value; |
@@ -2670,7 +2678,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, | |||
2670 | struct snd_soc_dapm_update update; | 2678 | struct snd_soc_dapm_update update; |
2671 | 2679 | ||
2672 | if (snd_soc_volsw_is_stereo(mc)) | 2680 | if (snd_soc_volsw_is_stereo(mc)) |
2673 | dev_warn(widget->dapm->dev, | 2681 | dev_warn(codec->dapm.dev, |
2674 | "ASoC: Control '%s' is stereo, which is not supported\n", | 2682 | "ASoC: Control '%s' is stereo, which is not supported\n", |
2675 | kcontrol->id.name); | 2683 | kcontrol->id.name); |
2676 | 2684 | ||
@@ -2684,7 +2692,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, | |||
2684 | 2692 | ||
2685 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | 2693 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2686 | 2694 | ||
2687 | change = snd_soc_test_bits(widget->codec, reg, mask, val); | 2695 | change = snd_soc_test_bits(codec, reg, mask, val); |
2688 | if (change) { | 2696 | if (change) { |
2689 | update.kcontrol = kcontrol; | 2697 | update.kcontrol = kcontrol; |
2690 | update.reg = reg; | 2698 | update.reg = reg; |
@@ -2715,12 +2723,11 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); | |||
2715 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, | 2723 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
2716 | struct snd_ctl_elem_value *ucontrol) | 2724 | struct snd_ctl_elem_value *ucontrol) |
2717 | { | 2725 | { |
2718 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2726 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
2719 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
2720 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | 2727 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
2721 | unsigned int val; | 2728 | unsigned int val; |
2722 | 2729 | ||
2723 | val = snd_soc_read(widget->codec, e->reg); | 2730 | val = snd_soc_read(codec, e->reg); |
2724 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask; | 2731 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask; |
2725 | if (e->shift_l != e->shift_r) | 2732 | if (e->shift_l != e->shift_r) |
2726 | ucontrol->value.enumerated.item[1] = | 2733 | ucontrol->value.enumerated.item[1] = |
@@ -2765,7 +2772,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, | |||
2765 | 2772 | ||
2766 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | 2773 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2767 | 2774 | ||
2768 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); | 2775 | change = snd_soc_test_bits(codec, e->reg, mask, val); |
2769 | if (change) { | 2776 | if (change) { |
2770 | widget->value = val; | 2777 | widget->value = val; |
2771 | 2778 | ||
@@ -2854,12 +2861,11 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); | |||
2854 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, | 2861 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
2855 | struct snd_ctl_elem_value *ucontrol) | 2862 | struct snd_ctl_elem_value *ucontrol) |
2856 | { | 2863 | { |
2857 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2864 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
2858 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
2859 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | 2865 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
2860 | unsigned int reg_val, val, mux; | 2866 | unsigned int reg_val, val, mux; |
2861 | 2867 | ||
2862 | reg_val = snd_soc_read(widget->codec, e->reg); | 2868 | reg_val = snd_soc_read(codec, e->reg); |
2863 | val = (reg_val >> e->shift_l) & e->mask; | 2869 | val = (reg_val >> e->shift_l) & e->mask; |
2864 | for (mux = 0; mux < e->max; mux++) { | 2870 | for (mux = 0; mux < e->max; mux++) { |
2865 | if (val == e->values[mux]) | 2871 | if (val == e->values[mux]) |
@@ -2918,7 +2924,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, | |||
2918 | 2924 | ||
2919 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | 2925 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2920 | 2926 | ||
2921 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); | 2927 | change = snd_soc_test_bits(codec, e->reg, mask, val); |
2922 | if (change) { | 2928 | if (change) { |
2923 | widget->value = val; | 2929 | widget->value = val; |
2924 | 2930 | ||