summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2018-01-28 22:05:45 -0500
committerMark Brown <broonie@kernel.org>2018-02-12 04:41:46 -0500
commite075fc17b70813fede562cc0f7751bc7ca426c49 (patch)
treefdf34188ec52b880ed4b9b7b59e4e9f475450f7b
parent7928b2cbe55b2a410a0f5c1f154610059c57b1b2 (diff)
ASoC: wm8960: replace codec to component
Now we can replace Codec to Component. Let's do it. Note: xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 0 -> .idle_bias_on = 1 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/wm8960.c249
1 files changed, 126 insertions, 123 deletions
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 9ed455700954..c30f5aa392c6 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -49,7 +49,7 @@
49#define WM8960_DRES_MASK 0x30 49#define WM8960_DRES_MASK 0x30
50 50
51static bool is_pll_freq_available(unsigned int source, unsigned int target); 51static bool is_pll_freq_available(unsigned int source, unsigned int target);
52static int wm8960_set_pll(struct snd_soc_codec *codec, 52static int wm8960_set_pll(struct snd_soc_component *component,
53 unsigned int freq_in, unsigned int freq_out); 53 unsigned int freq_in, unsigned int freq_out);
54/* 54/*
55 * wm8960 register cache 55 * wm8960 register cache
@@ -123,7 +123,7 @@ static bool wm8960_volatile(struct device *dev, unsigned int reg)
123struct wm8960_priv { 123struct wm8960_priv {
124 struct clk *mclk; 124 struct clk *mclk;
125 struct regmap *regmap; 125 struct regmap *regmap;
126 int (*set_bias_level)(struct snd_soc_codec *, 126 int (*set_bias_level)(struct snd_soc_component *,
127 enum snd_soc_bias_level level); 127 enum snd_soc_bias_level level);
128 struct snd_soc_dapm_widget *lout1; 128 struct snd_soc_dapm_widget *lout1;
129 struct snd_soc_dapm_widget *rout1; 129 struct snd_soc_dapm_widget *rout1;
@@ -168,9 +168,9 @@ static const struct soc_enum wm8960_enum[] = {
168 168
169static const int deemph_settings[] = { 0, 32000, 44100, 48000 }; 169static const int deemph_settings[] = { 0, 32000, 44100, 48000 };
170 170
171static int wm8960_set_deemph(struct snd_soc_codec *codec) 171static int wm8960_set_deemph(struct snd_soc_component *component)
172{ 172{
173 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 173 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
174 int val, i, best; 174 int val, i, best;
175 175
176 /* If we're using deemphasis select the nearest available sample 176 /* If we're using deemphasis select the nearest available sample
@@ -189,17 +189,17 @@ static int wm8960_set_deemph(struct snd_soc_codec *codec)
189 val = 0; 189 val = 0;
190 } 190 }
191 191
192 dev_dbg(codec->dev, "Set deemphasis %d\n", val); 192 dev_dbg(component->dev, "Set deemphasis %d\n", val);
193 193
194 return snd_soc_update_bits(codec, WM8960_DACCTL1, 194 return snd_soc_component_update_bits(component, WM8960_DACCTL1,
195 0x6, val); 195 0x6, val);
196} 196}
197 197
198static int wm8960_get_deemph(struct snd_kcontrol *kcontrol, 198static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
199 struct snd_ctl_elem_value *ucontrol) 199 struct snd_ctl_elem_value *ucontrol)
200{ 200{
201 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 201 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
202 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 202 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
203 203
204 ucontrol->value.integer.value[0] = wm8960->deemph; 204 ucontrol->value.integer.value[0] = wm8960->deemph;
205 return 0; 205 return 0;
@@ -208,8 +208,8 @@ static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
208static int wm8960_put_deemph(struct snd_kcontrol *kcontrol, 208static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
209 struct snd_ctl_elem_value *ucontrol) 209 struct snd_ctl_elem_value *ucontrol)
210{ 210{
211 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 211 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
212 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 212 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
213 unsigned int deemph = ucontrol->value.integer.value[0]; 213 unsigned int deemph = ucontrol->value.integer.value[0];
214 214
215 if (deemph > 1) 215 if (deemph > 1)
@@ -217,7 +217,7 @@ static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
217 217
218 wm8960->deemph = deemph; 218 wm8960->deemph = deemph;
219 219
220 return wm8960_set_deemph(codec); 220 return wm8960_set_deemph(component);
221} 221}
222 222
223static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1); 223static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
@@ -470,11 +470,11 @@ static const struct snd_soc_dapm_route audio_paths_capless[] = {
470 { "OUT3 VMID", NULL, "Right Output Mixer" }, 470 { "OUT3 VMID", NULL, "Right Output Mixer" },
471}; 471};
472 472
473static int wm8960_add_widgets(struct snd_soc_codec *codec) 473static int wm8960_add_widgets(struct snd_soc_component *component)
474{ 474{
475 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 475 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
476 struct wm8960_data *pdata = &wm8960->pdata; 476 struct wm8960_data *pdata = &wm8960->pdata;
477 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); 477 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
478 struct snd_soc_dapm_widget *w; 478 struct snd_soc_dapm_widget *w;
479 479
480 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets, 480 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,
@@ -504,7 +504,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
504 * list each time to find the desired power state do so now 504 * list each time to find the desired power state do so now
505 * and save the result. 505 * and save the result.
506 */ 506 */
507 list_for_each_entry(w, &codec->component.card->widgets, list) { 507 list_for_each_entry(w, &component->card->widgets, list) {
508 if (w->dapm != dapm) 508 if (w->dapm != dapm)
509 continue; 509 continue;
510 if (strcmp(w->name, "LOUT1 PGA") == 0) 510 if (strcmp(w->name, "LOUT1 PGA") == 0)
@@ -521,7 +521,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
521static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai, 521static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai,
522 unsigned int fmt) 522 unsigned int fmt)
523{ 523{
524 struct snd_soc_codec *codec = codec_dai->codec; 524 struct snd_soc_component *component = codec_dai->component;
525 u16 iface = 0; 525 u16 iface = 0;
526 526
527 /* set master/slave audio interface */ 527 /* set master/slave audio interface */
@@ -573,7 +573,7 @@ static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai,
573 } 573 }
574 574
575 /* set iface */ 575 /* set iface */
576 snd_soc_write(codec, WM8960_IFACE1, iface); 576 snd_soc_component_write(component, WM8960_IFACE1, iface);
577 return 0; 577 return 0;
578} 578}
579 579
@@ -683,7 +683,7 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
683 * triplet, we relax the bclk such that bclk is chosen as the 683 * triplet, we relax the bclk such that bclk is chosen as the
684 * closest available frequency greater than expected bclk. 684 * closest available frequency greater than expected bclk.
685 * 685 *
686 * @codec: codec structure 686 * @component: component structure
687 * @freq_in: input frequency used to derive freq out via PLL 687 * @freq_in: input frequency used to derive freq out via PLL
688 * @sysclk_idx: sysclk_divs index for found sysclk 688 * @sysclk_idx: sysclk_divs index for found sysclk
689 * @dac_idx: dac_divs index for found lrclk 689 * @dac_idx: dac_divs index for found lrclk
@@ -695,10 +695,10 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
695 * (@sysclk_idx, @dac_idx, @bclk_idx) dividers 695 * (@sysclk_idx, @dac_idx, @bclk_idx) dividers
696 */ 696 */
697static 697static
698int wm8960_configure_pll(struct snd_soc_codec *codec, int freq_in, 698int wm8960_configure_pll(struct snd_soc_component *component, int freq_in,
699 int *sysclk_idx, int *dac_idx, int *bclk_idx) 699 int *sysclk_idx, int *dac_idx, int *bclk_idx)
700{ 700{
701 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 701 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
702 int sysclk, bclk, lrclk, freq_out; 702 int sysclk, bclk, lrclk, freq_out;
703 int diff, closest, best_freq_out; 703 int diff, closest, best_freq_out;
704 int i, j, k; 704 int i, j, k;
@@ -741,22 +741,22 @@ int wm8960_configure_pll(struct snd_soc_codec *codec, int freq_in,
741 741
742 return best_freq_out; 742 return best_freq_out;
743} 743}
744static int wm8960_configure_clocking(struct snd_soc_codec *codec) 744static int wm8960_configure_clocking(struct snd_soc_component *component)
745{ 745{
746 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 746 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
747 int freq_out, freq_in; 747 int freq_out, freq_in;
748 u16 iface1 = snd_soc_read(codec, WM8960_IFACE1); 748 u16 iface1 = snd_soc_component_read32(component, WM8960_IFACE1);
749 int i, j, k; 749 int i, j, k;
750 int ret; 750 int ret;
751 751
752 if (!(iface1 & (1<<6))) { 752 if (!(iface1 & (1<<6))) {
753 dev_dbg(codec->dev, 753 dev_dbg(component->dev,
754 "Codec is slave mode, no need to configure clock\n"); 754 "Codec is slave mode, no need to configure clock\n");
755 return 0; 755 return 0;
756 } 756 }
757 757
758 if (wm8960->clk_id != WM8960_SYSCLK_MCLK && !wm8960->freq_in) { 758 if (wm8960->clk_id != WM8960_SYSCLK_MCLK && !wm8960->freq_in) {
759 dev_err(codec->dev, "No MCLK configured\n"); 759 dev_err(component->dev, "No MCLK configured\n");
760 return -EINVAL; 760 return -EINVAL;
761 } 761 }
762 762
@@ -769,12 +769,12 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
769 */ 769 */
770 if (wm8960->clk_id == WM8960_SYSCLK_AUTO) { 770 if (wm8960->clk_id == WM8960_SYSCLK_AUTO) {
771 /* disable the PLL and using MCLK to provide sysclk */ 771 /* disable the PLL and using MCLK to provide sysclk */
772 wm8960_set_pll(codec, 0, 0); 772 wm8960_set_pll(component, 0, 0);
773 freq_out = freq_in; 773 freq_out = freq_in;
774 } else if (wm8960->sysclk) { 774 } else if (wm8960->sysclk) {
775 freq_out = wm8960->sysclk; 775 freq_out = wm8960->sysclk;
776 } else { 776 } else {
777 dev_err(codec->dev, "No SYSCLK configured\n"); 777 dev_err(component->dev, "No SYSCLK configured\n");
778 return -EINVAL; 778 return -EINVAL;
779 } 779 }
780 780
@@ -783,28 +783,28 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
783 if (ret >= 0) { 783 if (ret >= 0) {
784 goto configure_clock; 784 goto configure_clock;
785 } else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) { 785 } else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) {
786 dev_err(codec->dev, "failed to configure clock\n"); 786 dev_err(component->dev, "failed to configure clock\n");
787 return -EINVAL; 787 return -EINVAL;
788 } 788 }
789 } 789 }
790 790
791 freq_out = wm8960_configure_pll(codec, freq_in, &i, &j, &k); 791 freq_out = wm8960_configure_pll(component, freq_in, &i, &j, &k);
792 if (freq_out < 0) { 792 if (freq_out < 0) {
793 dev_err(codec->dev, "failed to configure clock via PLL\n"); 793 dev_err(component->dev, "failed to configure clock via PLL\n");
794 return freq_out; 794 return freq_out;
795 } 795 }
796 wm8960_set_pll(codec, freq_in, freq_out); 796 wm8960_set_pll(component, freq_in, freq_out);
797 797
798configure_clock: 798configure_clock:
799 /* configure sysclk clock */ 799 /* configure sysclk clock */
800 snd_soc_update_bits(codec, WM8960_CLOCK1, 3 << 1, i << 1); 800 snd_soc_component_update_bits(component, WM8960_CLOCK1, 3 << 1, i << 1);
801 801
802 /* configure frame clock */ 802 /* configure frame clock */
803 snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 3, j << 3); 803 snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x7 << 3, j << 3);
804 snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 6, j << 6); 804 snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x7 << 6, j << 6);
805 805
806 /* configure bit clock */ 806 /* configure bit clock */
807 snd_soc_update_bits(codec, WM8960_CLOCK2, 0xf, k); 807 snd_soc_component_update_bits(component, WM8960_CLOCK2, 0xf, k);
808 808
809 return 0; 809 return 0;
810} 810}
@@ -813,9 +813,9 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
813 struct snd_pcm_hw_params *params, 813 struct snd_pcm_hw_params *params,
814 struct snd_soc_dai *dai) 814 struct snd_soc_dai *dai)
815{ 815{
816 struct snd_soc_codec *codec = dai->codec; 816 struct snd_soc_component *component = dai->component;
817 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 817 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
818 u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; 818 u16 iface = snd_soc_component_read32(component, WM8960_IFACE1) & 0xfff3;
819 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 819 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
820 int i; 820 int i;
821 821
@@ -840,7 +840,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
840 break; 840 break;
841 } 841 }
842 default: 842 default:
843 dev_err(codec->dev, "unsupported width %d\n", 843 dev_err(component->dev, "unsupported width %d\n",
844 params_width(params)); 844 params_width(params));
845 return -EINVAL; 845 return -EINVAL;
846 } 846 }
@@ -848,23 +848,23 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
848 wm8960->lrclk = params_rate(params); 848 wm8960->lrclk = params_rate(params);
849 /* Update filters for the new rate */ 849 /* Update filters for the new rate */
850 if (tx) { 850 if (tx) {
851 wm8960_set_deemph(codec); 851 wm8960_set_deemph(component);
852 } else { 852 } else {
853 for (i = 0; i < ARRAY_SIZE(alc_rates); i++) 853 for (i = 0; i < ARRAY_SIZE(alc_rates); i++)
854 if (alc_rates[i].rate == params_rate(params)) 854 if (alc_rates[i].rate == params_rate(params))
855 snd_soc_update_bits(codec, 855 snd_soc_component_update_bits(component,
856 WM8960_ADDCTL3, 0x7, 856 WM8960_ADDCTL3, 0x7,
857 alc_rates[i].val); 857 alc_rates[i].val);
858 } 858 }
859 859
860 /* set iface */ 860 /* set iface */
861 snd_soc_write(codec, WM8960_IFACE1, iface); 861 snd_soc_component_write(component, WM8960_IFACE1, iface);
862 862
863 wm8960->is_stream_in_use[tx] = true; 863 wm8960->is_stream_in_use[tx] = true;
864 864
865 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON && 865 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON &&
866 !wm8960->is_stream_in_use[!tx]) 866 !wm8960->is_stream_in_use[!tx])
867 return wm8960_configure_clocking(codec); 867 return wm8960_configure_clocking(component);
868 868
869 return 0; 869 return 0;
870} 870}
@@ -872,8 +872,8 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
872static int wm8960_hw_free(struct snd_pcm_substream *substream, 872static int wm8960_hw_free(struct snd_pcm_substream *substream,
873 struct snd_soc_dai *dai) 873 struct snd_soc_dai *dai)
874{ 874{
875 struct snd_soc_codec *codec = dai->codec; 875 struct snd_soc_component *component = dai->component;
876 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 876 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
877 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 877 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
878 878
879 wm8960->is_stream_in_use[tx] = false; 879 wm8960->is_stream_in_use[tx] = false;
@@ -883,20 +883,20 @@ static int wm8960_hw_free(struct snd_pcm_substream *substream,
883 883
884static int wm8960_mute(struct snd_soc_dai *dai, int mute) 884static int wm8960_mute(struct snd_soc_dai *dai, int mute)
885{ 885{
886 struct snd_soc_codec *codec = dai->codec; 886 struct snd_soc_component *component = dai->component;
887 887
888 if (mute) 888 if (mute)
889 snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0x8); 889 snd_soc_component_update_bits(component, WM8960_DACCTL1, 0x8, 0x8);
890 else 890 else
891 snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0); 891 snd_soc_component_update_bits(component, WM8960_DACCTL1, 0x8, 0);
892 return 0; 892 return 0;
893} 893}
894 894
895static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec, 895static int wm8960_set_bias_level_out3(struct snd_soc_component *component,
896 enum snd_soc_bias_level level) 896 enum snd_soc_bias_level level)
897{ 897{
898 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 898 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
899 u16 pm2 = snd_soc_read(codec, WM8960_POWER2); 899 u16 pm2 = snd_soc_component_read32(component, WM8960_POWER2);
900 int ret; 900 int ret;
901 901
902 switch (level) { 902 switch (level) {
@@ -904,24 +904,24 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
904 break; 904 break;
905 905
906 case SND_SOC_BIAS_PREPARE: 906 case SND_SOC_BIAS_PREPARE:
907 switch (snd_soc_codec_get_bias_level(codec)) { 907 switch (snd_soc_component_get_bias_level(component)) {
908 case SND_SOC_BIAS_STANDBY: 908 case SND_SOC_BIAS_STANDBY:
909 if (!IS_ERR(wm8960->mclk)) { 909 if (!IS_ERR(wm8960->mclk)) {
910 ret = clk_prepare_enable(wm8960->mclk); 910 ret = clk_prepare_enable(wm8960->mclk);
911 if (ret) { 911 if (ret) {
912 dev_err(codec->dev, 912 dev_err(component->dev,
913 "Failed to enable MCLK: %d\n", 913 "Failed to enable MCLK: %d\n",
914 ret); 914 ret);
915 return ret; 915 return ret;
916 } 916 }
917 } 917 }
918 918
919 ret = wm8960_configure_clocking(codec); 919 ret = wm8960_configure_clocking(component);
920 if (ret) 920 if (ret)
921 return ret; 921 return ret;
922 922
923 /* Set VMID to 2x50k */ 923 /* Set VMID to 2x50k */
924 snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80); 924 snd_soc_component_update_bits(component, WM8960_POWER1, 0x180, 0x80);
925 break; 925 break;
926 926
927 case SND_SOC_BIAS_ON: 927 case SND_SOC_BIAS_ON:
@@ -930,7 +930,7 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
930 * disable the pll 930 * disable the pll
931 */ 931 */
932 if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1)) 932 if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1))
933 wm8960_set_pll(codec, 0, 0); 933 wm8960_set_pll(component, 0, 0);
934 934
935 if (!IS_ERR(wm8960->mclk)) 935 if (!IS_ERR(wm8960->mclk))
936 clk_disable_unprepare(wm8960->mclk); 936 clk_disable_unprepare(wm8960->mclk);
@@ -943,38 +943,38 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
943 break; 943 break;
944 944
945 case SND_SOC_BIAS_STANDBY: 945 case SND_SOC_BIAS_STANDBY:
946 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { 946 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
947 regcache_sync(wm8960->regmap); 947 regcache_sync(wm8960->regmap);
948 948
949 /* Enable anti-pop features */ 949 /* Enable anti-pop features */
950 snd_soc_write(codec, WM8960_APOP1, 950 snd_soc_component_write(component, WM8960_APOP1,
951 WM8960_POBCTRL | WM8960_SOFT_ST | 951 WM8960_POBCTRL | WM8960_SOFT_ST |
952 WM8960_BUFDCOPEN | WM8960_BUFIOEN); 952 WM8960_BUFDCOPEN | WM8960_BUFIOEN);
953 953
954 /* Enable & ramp VMID at 2x50k */ 954 /* Enable & ramp VMID at 2x50k */
955 snd_soc_update_bits(codec, WM8960_POWER1, 0x80, 0x80); 955 snd_soc_component_update_bits(component, WM8960_POWER1, 0x80, 0x80);
956 msleep(100); 956 msleep(100);
957 957
958 /* Enable VREF */ 958 /* Enable VREF */
959 snd_soc_update_bits(codec, WM8960_POWER1, WM8960_VREF, 959 snd_soc_component_update_bits(component, WM8960_POWER1, WM8960_VREF,
960 WM8960_VREF); 960 WM8960_VREF);
961 961
962 /* Disable anti-pop features */ 962 /* Disable anti-pop features */
963 snd_soc_write(codec, WM8960_APOP1, WM8960_BUFIOEN); 963 snd_soc_component_write(component, WM8960_APOP1, WM8960_BUFIOEN);
964 } 964 }
965 965
966 /* Set VMID to 2x250k */ 966 /* Set VMID to 2x250k */
967 snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x100); 967 snd_soc_component_update_bits(component, WM8960_POWER1, 0x180, 0x100);
968 break; 968 break;
969 969
970 case SND_SOC_BIAS_OFF: 970 case SND_SOC_BIAS_OFF:
971 /* Enable anti-pop features */ 971 /* Enable anti-pop features */
972 snd_soc_write(codec, WM8960_APOP1, 972 snd_soc_component_write(component, WM8960_APOP1,
973 WM8960_POBCTRL | WM8960_SOFT_ST | 973 WM8960_POBCTRL | WM8960_SOFT_ST |
974 WM8960_BUFDCOPEN | WM8960_BUFIOEN); 974 WM8960_BUFDCOPEN | WM8960_BUFIOEN);
975 975
976 /* Disable VMID and VREF, let them discharge */ 976 /* Disable VMID and VREF, let them discharge */
977 snd_soc_write(codec, WM8960_POWER1, 0); 977 snd_soc_component_write(component, WM8960_POWER1, 0);
978 msleep(600); 978 msleep(600);
979 break; 979 break;
980 } 980 }
@@ -982,11 +982,11 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
982 return 0; 982 return 0;
983} 983}
984 984
985static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec, 985static int wm8960_set_bias_level_capless(struct snd_soc_component *component,
986 enum snd_soc_bias_level level) 986 enum snd_soc_bias_level level)
987{ 987{
988 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 988 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
989 u16 pm2 = snd_soc_read(codec, WM8960_POWER2); 989 u16 pm2 = snd_soc_component_read32(component, WM8960_POWER2);
990 int reg, ret; 990 int reg, ret;
991 991
992 switch (level) { 992 switch (level) {
@@ -994,10 +994,10 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
994 break; 994 break;
995 995
996 case SND_SOC_BIAS_PREPARE: 996 case SND_SOC_BIAS_PREPARE:
997 switch (snd_soc_codec_get_bias_level(codec)) { 997 switch (snd_soc_component_get_bias_level(component)) {
998 case SND_SOC_BIAS_STANDBY: 998 case SND_SOC_BIAS_STANDBY:
999 /* Enable anti pop mode */ 999 /* Enable anti pop mode */
1000 snd_soc_update_bits(codec, WM8960_APOP1, 1000 snd_soc_component_update_bits(component, WM8960_APOP1,
1001 WM8960_POBCTRL | WM8960_SOFT_ST | 1001 WM8960_POBCTRL | WM8960_SOFT_ST |
1002 WM8960_BUFDCOPEN, 1002 WM8960_BUFDCOPEN,
1003 WM8960_POBCTRL | WM8960_SOFT_ST | 1003 WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -1011,20 +1011,20 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
1011 reg |= WM8960_PWR2_ROUT1; 1011 reg |= WM8960_PWR2_ROUT1;
1012 if (wm8960->out3 && wm8960->out3->power) 1012 if (wm8960->out3 && wm8960->out3->power)
1013 reg |= WM8960_PWR2_OUT3; 1013 reg |= WM8960_PWR2_OUT3;
1014 snd_soc_update_bits(codec, WM8960_POWER2, 1014 snd_soc_component_update_bits(component, WM8960_POWER2,
1015 WM8960_PWR2_LOUT1 | 1015 WM8960_PWR2_LOUT1 |
1016 WM8960_PWR2_ROUT1 | 1016 WM8960_PWR2_ROUT1 |
1017 WM8960_PWR2_OUT3, reg); 1017 WM8960_PWR2_OUT3, reg);
1018 1018
1019 /* Enable VMID at 2*50k */ 1019 /* Enable VMID at 2*50k */
1020 snd_soc_update_bits(codec, WM8960_POWER1, 1020 snd_soc_component_update_bits(component, WM8960_POWER1,
1021 WM8960_VMID_MASK, 0x80); 1021 WM8960_VMID_MASK, 0x80);
1022 1022
1023 /* Ramp */ 1023 /* Ramp */
1024 msleep(100); 1024 msleep(100);
1025 1025
1026 /* Enable VREF */ 1026 /* Enable VREF */
1027 snd_soc_update_bits(codec, WM8960_POWER1, 1027 snd_soc_component_update_bits(component, WM8960_POWER1,
1028 WM8960_VREF, WM8960_VREF); 1028 WM8960_VREF, WM8960_VREF);
1029 1029
1030 msleep(100); 1030 msleep(100);
@@ -1032,14 +1032,14 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
1032 if (!IS_ERR(wm8960->mclk)) { 1032 if (!IS_ERR(wm8960->mclk)) {
1033 ret = clk_prepare_enable(wm8960->mclk); 1033 ret = clk_prepare_enable(wm8960->mclk);
1034 if (ret) { 1034 if (ret) {
1035 dev_err(codec->dev, 1035 dev_err(component->dev,
1036 "Failed to enable MCLK: %d\n", 1036 "Failed to enable MCLK: %d\n",
1037 ret); 1037 ret);
1038 return ret; 1038 return ret;
1039 } 1039 }
1040 } 1040 }
1041 1041
1042 ret = wm8960_configure_clocking(codec); 1042 ret = wm8960_configure_clocking(component);
1043 if (ret) 1043 if (ret)
1044 return ret; 1044 return ret;
1045 1045
@@ -1051,20 +1051,20 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
1051 * disable the pll 1051 * disable the pll
1052 */ 1052 */
1053 if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1)) 1053 if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1))
1054 wm8960_set_pll(codec, 0, 0); 1054 wm8960_set_pll(component, 0, 0);
1055 1055
1056 if (!IS_ERR(wm8960->mclk)) 1056 if (!IS_ERR(wm8960->mclk))
1057 clk_disable_unprepare(wm8960->mclk); 1057 clk_disable_unprepare(wm8960->mclk);
1058 1058
1059 /* Enable anti-pop mode */ 1059 /* Enable anti-pop mode */
1060 snd_soc_update_bits(codec, WM8960_APOP1, 1060 snd_soc_component_update_bits(component, WM8960_APOP1,
1061 WM8960_POBCTRL | WM8960_SOFT_ST | 1061 WM8960_POBCTRL | WM8960_SOFT_ST |
1062 WM8960_BUFDCOPEN, 1062 WM8960_BUFDCOPEN,
1063 WM8960_POBCTRL | WM8960_SOFT_ST | 1063 WM8960_POBCTRL | WM8960_SOFT_ST |
1064 WM8960_BUFDCOPEN); 1064 WM8960_BUFDCOPEN);
1065 1065
1066 /* Disable VMID and VREF */ 1066 /* Disable VMID and VREF */
1067 snd_soc_update_bits(codec, WM8960_POWER1, 1067 snd_soc_component_update_bits(component, WM8960_POWER1,
1068 WM8960_VREF | WM8960_VMID_MASK, 0); 1068 WM8960_VREF | WM8960_VMID_MASK, 0);
1069 break; 1069 break;
1070 1070
@@ -1077,15 +1077,15 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
1077 break; 1077 break;
1078 1078
1079 case SND_SOC_BIAS_STANDBY: 1079 case SND_SOC_BIAS_STANDBY:
1080 switch (snd_soc_codec_get_bias_level(codec)) { 1080 switch (snd_soc_component_get_bias_level(component)) {
1081 case SND_SOC_BIAS_PREPARE: 1081 case SND_SOC_BIAS_PREPARE:
1082 /* Disable HP discharge */ 1082 /* Disable HP discharge */
1083 snd_soc_update_bits(codec, WM8960_APOP2, 1083 snd_soc_component_update_bits(component, WM8960_APOP2,
1084 WM8960_DISOP | WM8960_DRES_MASK, 1084 WM8960_DISOP | WM8960_DRES_MASK,
1085 0); 1085 0);
1086 1086
1087 /* Disable anti-pop features */ 1087 /* Disable anti-pop features */
1088 snd_soc_update_bits(codec, WM8960_APOP1, 1088 snd_soc_component_update_bits(component, WM8960_APOP1,
1089 WM8960_POBCTRL | WM8960_SOFT_ST | 1089 WM8960_POBCTRL | WM8960_SOFT_ST |
1090 WM8960_BUFDCOPEN, 1090 WM8960_BUFDCOPEN,
1091 WM8960_POBCTRL | WM8960_SOFT_ST | 1091 WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -1184,7 +1184,7 @@ static int pll_factors(unsigned int source, unsigned int target,
1184 return 0; 1184 return 0;
1185} 1185}
1186 1186
1187static int wm8960_set_pll(struct snd_soc_codec *codec, 1187static int wm8960_set_pll(struct snd_soc_component *component,
1188 unsigned int freq_in, unsigned int freq_out) 1188 unsigned int freq_in, unsigned int freq_out)
1189{ 1189{
1190 u16 reg; 1190 u16 reg;
@@ -1199,29 +1199,29 @@ static int wm8960_set_pll(struct snd_soc_codec *codec,
1199 1199
1200 /* Disable the PLL: even if we are changing the frequency the 1200 /* Disable the PLL: even if we are changing the frequency the
1201 * PLL needs to be disabled while we do so. */ 1201 * PLL needs to be disabled while we do so. */
1202 snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0); 1202 snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x1, 0);
1203 snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0); 1203 snd_soc_component_update_bits(component, WM8960_POWER2, 0x1, 0);
1204 1204
1205 if (!freq_in || !freq_out) 1205 if (!freq_in || !freq_out)
1206 return 0; 1206 return 0;
1207 1207
1208 reg = snd_soc_read(codec, WM8960_PLL1) & ~0x3f; 1208 reg = snd_soc_component_read32(component, WM8960_PLL1) & ~0x3f;
1209 reg |= pll_div.pre_div << 4; 1209 reg |= pll_div.pre_div << 4;
1210 reg |= pll_div.n; 1210 reg |= pll_div.n;
1211 1211
1212 if (pll_div.k) { 1212 if (pll_div.k) {
1213 reg |= 0x20; 1213 reg |= 0x20;
1214 1214
1215 snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 16) & 0xff); 1215 snd_soc_component_write(component, WM8960_PLL2, (pll_div.k >> 16) & 0xff);
1216 snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 8) & 0xff); 1216 snd_soc_component_write(component, WM8960_PLL3, (pll_div.k >> 8) & 0xff);
1217 snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0xff); 1217 snd_soc_component_write(component, WM8960_PLL4, pll_div.k & 0xff);
1218 } 1218 }
1219 snd_soc_write(codec, WM8960_PLL1, reg); 1219 snd_soc_component_write(component, WM8960_PLL1, reg);
1220 1220
1221 /* Turn it on */ 1221 /* Turn it on */
1222 snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0x1); 1222 snd_soc_component_update_bits(component, WM8960_POWER2, 0x1, 0x1);
1223 msleep(250); 1223 msleep(250);
1224 snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0x1); 1224 snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x1, 0x1);
1225 1225
1226 return 0; 1226 return 0;
1227} 1227}
@@ -1229,43 +1229,43 @@ static int wm8960_set_pll(struct snd_soc_codec *codec,
1229static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, 1229static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1230 int source, unsigned int freq_in, unsigned int freq_out) 1230 int source, unsigned int freq_in, unsigned int freq_out)
1231{ 1231{
1232 struct snd_soc_codec *codec = codec_dai->codec; 1232 struct snd_soc_component *component = codec_dai->component;
1233 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 1233 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
1234 1234
1235 wm8960->freq_in = freq_in; 1235 wm8960->freq_in = freq_in;
1236 1236
1237 if (pll_id == WM8960_SYSCLK_AUTO) 1237 if (pll_id == WM8960_SYSCLK_AUTO)
1238 return 0; 1238 return 0;
1239 1239
1240 return wm8960_set_pll(codec, freq_in, freq_out); 1240 return wm8960_set_pll(component, freq_in, freq_out);
1241} 1241}
1242 1242
1243static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai, 1243static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
1244 int div_id, int div) 1244 int div_id, int div)
1245{ 1245{
1246 struct snd_soc_codec *codec = codec_dai->codec; 1246 struct snd_soc_component *component = codec_dai->component;
1247 u16 reg; 1247 u16 reg;
1248 1248
1249 switch (div_id) { 1249 switch (div_id) {
1250 case WM8960_SYSCLKDIV: 1250 case WM8960_SYSCLKDIV:
1251 reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1f9; 1251 reg = snd_soc_component_read32(component, WM8960_CLOCK1) & 0x1f9;
1252 snd_soc_write(codec, WM8960_CLOCK1, reg | div); 1252 snd_soc_component_write(component, WM8960_CLOCK1, reg | div);
1253 break; 1253 break;
1254 case WM8960_DACDIV: 1254 case WM8960_DACDIV:
1255 reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1c7; 1255 reg = snd_soc_component_read32(component, WM8960_CLOCK1) & 0x1c7;
1256 snd_soc_write(codec, WM8960_CLOCK1, reg | div); 1256 snd_soc_component_write(component, WM8960_CLOCK1, reg | div);
1257 break; 1257 break;
1258 case WM8960_OPCLKDIV: 1258 case WM8960_OPCLKDIV:
1259 reg = snd_soc_read(codec, WM8960_PLL1) & 0x03f; 1259 reg = snd_soc_component_read32(component, WM8960_PLL1) & 0x03f;
1260 snd_soc_write(codec, WM8960_PLL1, reg | div); 1260 snd_soc_component_write(component, WM8960_PLL1, reg | div);
1261 break; 1261 break;
1262 case WM8960_DCLKDIV: 1262 case WM8960_DCLKDIV:
1263 reg = snd_soc_read(codec, WM8960_CLOCK2) & 0x03f; 1263 reg = snd_soc_component_read32(component, WM8960_CLOCK2) & 0x03f;
1264 snd_soc_write(codec, WM8960_CLOCK2, reg | div); 1264 snd_soc_component_write(component, WM8960_CLOCK2, reg | div);
1265 break; 1265 break;
1266 case WM8960_TOCLKSEL: 1266 case WM8960_TOCLKSEL:
1267 reg = snd_soc_read(codec, WM8960_ADDCTL1) & 0x1fd; 1267 reg = snd_soc_component_read32(component, WM8960_ADDCTL1) & 0x1fd;
1268 snd_soc_write(codec, WM8960_ADDCTL1, reg | div); 1268 snd_soc_component_write(component, WM8960_ADDCTL1, reg | div);
1269 break; 1269 break;
1270 default: 1270 default:
1271 return -EINVAL; 1271 return -EINVAL;
@@ -1274,27 +1274,27 @@ static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
1274 return 0; 1274 return 0;
1275} 1275}
1276 1276
1277static int wm8960_set_bias_level(struct snd_soc_codec *codec, 1277static int wm8960_set_bias_level(struct snd_soc_component *component,
1278 enum snd_soc_bias_level level) 1278 enum snd_soc_bias_level level)
1279{ 1279{
1280 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 1280 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
1281 1281
1282 return wm8960->set_bias_level(codec, level); 1282 return wm8960->set_bias_level(component, level);
1283} 1283}
1284 1284
1285static int wm8960_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, 1285static int wm8960_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
1286 unsigned int freq, int dir) 1286 unsigned int freq, int dir)
1287{ 1287{
1288 struct snd_soc_codec *codec = dai->codec; 1288 struct snd_soc_component *component = dai->component;
1289 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 1289 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
1290 1290
1291 switch (clk_id) { 1291 switch (clk_id) {
1292 case WM8960_SYSCLK_MCLK: 1292 case WM8960_SYSCLK_MCLK:
1293 snd_soc_update_bits(codec, WM8960_CLOCK1, 1293 snd_soc_component_update_bits(component, WM8960_CLOCK1,
1294 0x1, WM8960_SYSCLK_MCLK); 1294 0x1, WM8960_SYSCLK_MCLK);
1295 break; 1295 break;
1296 case WM8960_SYSCLK_PLL: 1296 case WM8960_SYSCLK_PLL:
1297 snd_soc_update_bits(codec, WM8960_CLOCK1, 1297 snd_soc_component_update_bits(component, WM8960_CLOCK1,
1298 0x1, WM8960_SYSCLK_PLL); 1298 0x1, WM8960_SYSCLK_PLL);
1299 break; 1299 break;
1300 case WM8960_SYSCLK_AUTO: 1300 case WM8960_SYSCLK_AUTO:
@@ -1343,9 +1343,9 @@ static struct snd_soc_dai_driver wm8960_dai = {
1343 .symmetric_rates = 1, 1343 .symmetric_rates = 1,
1344}; 1344};
1345 1345
1346static int wm8960_probe(struct snd_soc_codec *codec) 1346static int wm8960_probe(struct snd_soc_component *component)
1347{ 1347{
1348 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 1348 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
1349 struct wm8960_data *pdata = &wm8960->pdata; 1349 struct wm8960_data *pdata = &wm8960->pdata;
1350 1350
1351 if (pdata->capless) 1351 if (pdata->capless)
@@ -1353,17 +1353,21 @@ static int wm8960_probe(struct snd_soc_codec *codec)
1353 else 1353 else
1354 wm8960->set_bias_level = wm8960_set_bias_level_out3; 1354 wm8960->set_bias_level = wm8960_set_bias_level_out3;
1355 1355
1356 snd_soc_add_codec_controls(codec, wm8960_snd_controls, 1356 snd_soc_add_component_controls(component, wm8960_snd_controls,
1357 ARRAY_SIZE(wm8960_snd_controls)); 1357 ARRAY_SIZE(wm8960_snd_controls));
1358 wm8960_add_widgets(codec); 1358 wm8960_add_widgets(component);
1359 1359
1360 return 0; 1360 return 0;
1361} 1361}
1362 1362
1363static const struct snd_soc_codec_driver soc_codec_dev_wm8960 = { 1363static const struct snd_soc_component_driver soc_component_dev_wm8960 = {
1364 .probe = wm8960_probe, 1364 .probe = wm8960_probe,
1365 .set_bias_level = wm8960_set_bias_level, 1365 .set_bias_level = wm8960_set_bias_level,
1366 .suspend_bias_off = true, 1366 .suspend_bias_off = 1,
1367 .idle_bias_on = 1,
1368 .use_pmdown_time = 1,
1369 .endianness = 1,
1370 .non_legacy_dai_naming = 1,
1367}; 1371};
1368 1372
1369static const struct regmap_config wm8960_regmap = { 1373static const struct regmap_config wm8960_regmap = {
@@ -1447,15 +1451,14 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
1447 1451
1448 i2c_set_clientdata(i2c, wm8960); 1452 i2c_set_clientdata(i2c, wm8960);
1449 1453
1450 ret = snd_soc_register_codec(&i2c->dev, 1454 ret = devm_snd_soc_register_component(&i2c->dev,
1451 &soc_codec_dev_wm8960, &wm8960_dai, 1); 1455 &soc_component_dev_wm8960, &wm8960_dai, 1);
1452 1456
1453 return ret; 1457 return ret;
1454} 1458}
1455 1459
1456static int wm8960_i2c_remove(struct i2c_client *client) 1460static int wm8960_i2c_remove(struct i2c_client *client)
1457{ 1461{
1458 snd_soc_unregister_codec(&client->dev);
1459 return 0; 1462 return 0;
1460} 1463}
1461 1464