~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/wm8731.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/codecs/wm8731.c (Version linux-6.11-rc3) and /sound/soc/codecs/wm8731.c (Version linux-5.17.15)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * wm8731.c  --  WM8731 ALSA SoC Audio driver       3  * wm8731.c  --  WM8731 ALSA SoC Audio driver
  4  *                                                  4  *
  5  * Copyright 2005 Openedhand Ltd.                   5  * Copyright 2005 Openedhand Ltd.
  6  * Copyright 2006-12 Wolfson Microelectronics,      6  * Copyright 2006-12 Wolfson Microelectronics, plc
  7  *                                                  7  *
  8  * Author: Richard Purdie <richard@openedhand.      8  * Author: Richard Purdie <richard@openedhand.com>
  9  *                                                  9  *
 10  * Based on wm8753.c by Liam Girdwood              10  * Based on wm8753.c by Liam Girdwood
 11  */                                                11  */
 12                                                    12 
 13 #include <linux/module.h>                          13 #include <linux/module.h>
 14 #include <linux/moduleparam.h>                     14 #include <linux/moduleparam.h>
 15 #include <linux/init.h>                            15 #include <linux/init.h>
 16 #include <linux/delay.h>                           16 #include <linux/delay.h>
 17 #include <linux/pm.h>                              17 #include <linux/pm.h>
                                                   >>  18 #include <linux/i2c.h>
 18 #include <linux/slab.h>                            19 #include <linux/slab.h>
 19 #include <linux/regmap.h>                          20 #include <linux/regmap.h>
 20 #include <linux/regulator/consumer.h>              21 #include <linux/regulator/consumer.h>
                                                   >>  22 #include <linux/spi/spi.h>
                                                   >>  23 #include <linux/of_device.h>
                                                   >>  24 #include <linux/mutex.h>
 21 #include <linux/clk.h>                             25 #include <linux/clk.h>
 22 #include <sound/core.h>                            26 #include <sound/core.h>
 23 #include <sound/pcm.h>                             27 #include <sound/pcm.h>
 24 #include <sound/pcm_params.h>                      28 #include <sound/pcm_params.h>
 25 #include <sound/soc.h>                             29 #include <sound/soc.h>
 26 #include <sound/initval.h>                         30 #include <sound/initval.h>
 27 #include <sound/tlv.h>                             31 #include <sound/tlv.h>
 28                                                    32 
 29 #include "wm8731.h"                                33 #include "wm8731.h"
 30                                                    34 
                                                   >>  35 #define WM8731_NUM_SUPPLIES 4
 31 static const char *wm8731_supply_names[WM8731_     36 static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
 32         "AVDD",                                    37         "AVDD",
 33         "HPVDD",                                   38         "HPVDD",
 34         "DCVDD",                                   39         "DCVDD",
 35         "DBVDD",                                   40         "DBVDD",
 36 };                                                 41 };
 37                                                    42 
                                                   >>  43 /* codec private data */
                                                   >>  44 struct wm8731_priv {
                                                   >>  45         struct regmap *regmap;
                                                   >>  46         struct clk *mclk;
                                                   >>  47         struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
                                                   >>  48         const struct snd_pcm_hw_constraint_list *constraints;
                                                   >>  49         unsigned int sysclk;
                                                   >>  50         int sysclk_type;
                                                   >>  51         int playback_fs;
                                                   >>  52         bool deemph;
                                                   >>  53 
                                                   >>  54         struct mutex lock;
                                                   >>  55 };
                                                   >>  56 
                                                   >>  57 
 38 /*                                                 58 /*
 39  * wm8731 register cache                           59  * wm8731 register cache
 40  */                                                60  */
 41 static const struct reg_default wm8731_reg_def     61 static const struct reg_default wm8731_reg_defaults[] = {
 42         { 0, 0x0097 },                             62         { 0, 0x0097 },
 43         { 1, 0x0097 },                             63         { 1, 0x0097 },
 44         { 2, 0x0079 },                             64         { 2, 0x0079 },
 45         { 3, 0x0079 },                             65         { 3, 0x0079 },
 46         { 4, 0x000a },                             66         { 4, 0x000a },
 47         { 5, 0x0008 },                             67         { 5, 0x0008 },
 48         { 6, 0x009f },                             68         { 6, 0x009f },
 49         { 7, 0x000a },                             69         { 7, 0x000a },
 50         { 8, 0x0000 },                             70         { 8, 0x0000 },
 51         { 9, 0x0000 },                             71         { 9, 0x0000 },
 52 };                                                 72 };
 53                                                    73 
 54 static bool wm8731_volatile(struct device *dev     74 static bool wm8731_volatile(struct device *dev, unsigned int reg)
 55 {                                                  75 {
 56         return reg == WM8731_RESET;                76         return reg == WM8731_RESET;
 57 }                                                  77 }
 58                                                    78 
 59 #define wm8731_reset(m) regmap_write(m, WM8731     79 #define wm8731_reset(m) regmap_write(m, WM8731_RESET, 0)
 60                                                    80 
 61 static const char *wm8731_input_select[] = {"L     81 static const char *wm8731_input_select[] = {"Line In", "Mic"};
 62                                                    82 
 63 static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum,     83 static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum,
 64                             WM8731_APANA, 2, w     84                             WM8731_APANA, 2, wm8731_input_select);
 65                                                    85 
 66 static int wm8731_deemph[] = { 0, 32000, 44100     86 static int wm8731_deemph[] = { 0, 32000, 44100, 48000 };
 67                                                    87 
 68 static int wm8731_set_deemph(struct snd_soc_co     88 static int wm8731_set_deemph(struct snd_soc_component *component)
 69 {                                                  89 {
 70         struct wm8731_priv *wm8731 = snd_soc_c     90         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
 71         int val, i, best;                          91         int val, i, best;
 72                                                    92 
 73         /* If we're using deemphasis select th     93         /* If we're using deemphasis select the nearest available sample
 74          * rate.                                   94          * rate.
 75          */                                        95          */
 76         if (wm8731->deemph) {                      96         if (wm8731->deemph) {
 77                 best = 1;                          97                 best = 1;
 78                 for (i = 2; i < ARRAY_SIZE(wm8     98                 for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) {
 79                         if (abs(wm8731_deemph[     99                         if (abs(wm8731_deemph[i] - wm8731->playback_fs) <
 80                             abs(wm8731_deemph[    100                             abs(wm8731_deemph[best] - wm8731->playback_fs))
 81                                 best = i;         101                                 best = i;
 82                 }                                 102                 }
 83                                                   103 
 84                 val = best << 1;                  104                 val = best << 1;
 85         } else {                                  105         } else {
 86                 best = 0;                         106                 best = 0;
 87                 val = 0;                          107                 val = 0;
 88         }                                         108         }
 89                                                   109 
 90         dev_dbg(component->dev, "Set deemphasi    110         dev_dbg(component->dev, "Set deemphasis %d (%dHz)\n",
 91                 best, wm8731_deemph[best]);       111                 best, wm8731_deemph[best]);
 92                                                   112 
 93         return snd_soc_component_update_bits(c    113         return snd_soc_component_update_bits(component, WM8731_APDIGI, 0x6, val);
 94 }                                                 114 }
 95                                                   115 
 96 static int wm8731_get_deemph(struct snd_kcontr    116 static int wm8731_get_deemph(struct snd_kcontrol *kcontrol,
 97                              struct snd_ctl_el    117                              struct snd_ctl_elem_value *ucontrol)
 98 {                                                 118 {
 99         struct snd_soc_component *component =     119         struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
100         struct wm8731_priv *wm8731 = snd_soc_c    120         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
101                                                   121 
102         ucontrol->value.integer.value[0] = wm8    122         ucontrol->value.integer.value[0] = wm8731->deemph;
103                                                   123 
104         return 0;                                 124         return 0;
105 }                                                 125 }
106                                                   126 
107 static int wm8731_put_deemph(struct snd_kcontr    127 static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
108                              struct snd_ctl_el    128                              struct snd_ctl_elem_value *ucontrol)
109 {                                                 129 {
110         struct snd_soc_component *component =     130         struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
111         struct wm8731_priv *wm8731 = snd_soc_c    131         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
112         unsigned int deemph = ucontrol->value.    132         unsigned int deemph = ucontrol->value.integer.value[0];
113         int ret = 0;                              133         int ret = 0;
114                                                   134 
115         if (deemph > 1)                           135         if (deemph > 1)
116                 return -EINVAL;                   136                 return -EINVAL;
117                                                   137 
118         mutex_lock(&wm8731->lock);                138         mutex_lock(&wm8731->lock);
119         if (wm8731->deemph != deemph) {           139         if (wm8731->deemph != deemph) {
120                 wm8731->deemph = deemph;          140                 wm8731->deemph = deemph;
121                                                   141 
122                 wm8731_set_deemph(component);     142                 wm8731_set_deemph(component);
123                                                   143 
124                 ret = 1;                          144                 ret = 1;
125         }                                         145         }
126         mutex_unlock(&wm8731->lock);              146         mutex_unlock(&wm8731->lock);
127                                                   147 
128         return ret;                               148         return ret;
129 }                                                 149 }
130                                                   150 
131 static const DECLARE_TLV_DB_SCALE(in_tlv, -345    151 static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0);
132 static const DECLARE_TLV_DB_SCALE(sidetone_tlv    152 static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0);
133 static const DECLARE_TLV_DB_SCALE(out_tlv, -12    153 static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
134 static const DECLARE_TLV_DB_SCALE(mic_tlv, 0,     154 static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 2000, 0);
135                                                   155 
136 static const struct snd_kcontrol_new wm8731_sn    156 static const struct snd_kcontrol_new wm8731_snd_controls[] = {
137                                                   157 
138 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8    158 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V,
139                  0, 127, 0, out_tlv),             159                  0, 127, 0, out_tlv),
140 SOC_DOUBLE_R("Master Playback ZC Switch", WM87    160 SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V,
141         7, 1, 0),                                 161         7, 1, 0),
142                                                   162 
143 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINV    163 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0,
144                  in_tlv),                         164                  in_tlv),
145 SOC_DOUBLE_R("Line Capture Switch", WM8731_LIN    165 SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1),
146                                                   166 
147 SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APAN    167 SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA, 0, 1, 0, mic_tlv),
148 SOC_SINGLE("Mic Capture Switch", WM8731_APANA,    168 SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1),
149                                                   169 
150 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8    170 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
151                sidetone_tlv),                     171                sidetone_tlv),
152                                                   172 
153 SOC_SINGLE("ADC High Pass Filter Switch", WM87    173 SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1),
154 SOC_SINGLE("Store DC Offset Switch", WM8731_AP    174 SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),
155                                                   175 
156 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switc    176 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
157                     wm8731_get_deemph, wm8731_    177                     wm8731_get_deemph, wm8731_put_deemph),
158 };                                                178 };
159                                                   179 
160 /* Output Mixer */                                180 /* Output Mixer */
161 static const struct snd_kcontrol_new wm8731_ou    181 static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = {
162 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_A    182 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
163 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_    183 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
164 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731    184 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
165 };                                                185 };
166                                                   186 
167 /* Input mux */                                   187 /* Input mux */
168 static const struct snd_kcontrol_new wm8731_in    188 static const struct snd_kcontrol_new wm8731_input_mux_controls =
169 SOC_DAPM_ENUM("Input Select", wm8731_insel_enu    189 SOC_DAPM_ENUM("Input Select", wm8731_insel_enum);
170                                                   190 
171 static const struct snd_soc_dapm_widget wm8731    191 static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
172 SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE, 0,    192 SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE, 0, 0, NULL, 0),
173 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, N    193 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0),
174 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR,    194 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1,
175         &wm8731_output_mixer_controls[0],         195         &wm8731_output_mixer_controls[0],
176         ARRAY_SIZE(wm8731_output_mixer_control    196         ARRAY_SIZE(wm8731_output_mixer_controls)),
177 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM873    197 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR, 3, 1),
178 SND_SOC_DAPM_OUTPUT("LOUT"),                      198 SND_SOC_DAPM_OUTPUT("LOUT"),
179 SND_SOC_DAPM_OUTPUT("LHPOUT"),                    199 SND_SOC_DAPM_OUTPUT("LHPOUT"),
180 SND_SOC_DAPM_OUTPUT("ROUT"),                      200 SND_SOC_DAPM_OUTPUT("ROUT"),
181 SND_SOC_DAPM_OUTPUT("RHPOUT"),                    201 SND_SOC_DAPM_OUTPUT("RHPOUT"),
182 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731    202 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR, 2, 1),
183 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0,    203 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &wm8731_input_mux_controls),
184 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0,     204 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0, 1, NULL, 0),
185 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1    205 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1, 1),
186 SND_SOC_DAPM_INPUT("MICIN"),                      206 SND_SOC_DAPM_INPUT("MICIN"),
187 SND_SOC_DAPM_INPUT("RLINEIN"),                    207 SND_SOC_DAPM_INPUT("RLINEIN"),
188 SND_SOC_DAPM_INPUT("LLINEIN"),                    208 SND_SOC_DAPM_INPUT("LLINEIN"),
189 };                                                209 };
190                                                   210 
191 static int wm8731_check_osc(struct snd_soc_dap    211 static int wm8731_check_osc(struct snd_soc_dapm_widget *source,
192                             struct snd_soc_dap    212                             struct snd_soc_dapm_widget *sink)
193 {                                                 213 {
194         struct snd_soc_component *component =     214         struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
195         struct wm8731_priv *wm8731 = snd_soc_c    215         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
196                                                   216 
197         return wm8731->sysclk_type == WM8731_S    217         return wm8731->sysclk_type == WM8731_SYSCLK_XTAL;
198 }                                                 218 }
199                                                   219 
200 static const struct snd_soc_dapm_route wm8731_    220 static const struct snd_soc_dapm_route wm8731_intercon[] = {
201         {"DAC", NULL, "OSC", wm8731_check_osc}    221         {"DAC", NULL, "OSC", wm8731_check_osc},
202         {"ADC", NULL, "OSC", wm8731_check_osc}    222         {"ADC", NULL, "OSC", wm8731_check_osc},
203         {"DAC", NULL, "ACTIVE"},                  223         {"DAC", NULL, "ACTIVE"},
204         {"ADC", NULL, "ACTIVE"},                  224         {"ADC", NULL, "ACTIVE"},
205                                                   225 
206         /* output mixer */                        226         /* output mixer */
207         {"Output Mixer", "Line Bypass Switch",    227         {"Output Mixer", "Line Bypass Switch", "Line Input"},
208         {"Output Mixer", "HiFi Playback Switch    228         {"Output Mixer", "HiFi Playback Switch", "DAC"},
209         {"Output Mixer", "Mic Sidetone Switch"    229         {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
210                                                   230 
211         /* outputs */                             231         /* outputs */
212         {"RHPOUT", NULL, "Output Mixer"},         232         {"RHPOUT", NULL, "Output Mixer"},
213         {"ROUT", NULL, "Output Mixer"},           233         {"ROUT", NULL, "Output Mixer"},
214         {"LHPOUT", NULL, "Output Mixer"},         234         {"LHPOUT", NULL, "Output Mixer"},
215         {"LOUT", NULL, "Output Mixer"},           235         {"LOUT", NULL, "Output Mixer"},
216                                                   236 
217         /* input mux */                           237         /* input mux */
218         {"Input Mux", "Line In", "Line Input"}    238         {"Input Mux", "Line In", "Line Input"},
219         {"Input Mux", "Mic", "Mic Bias"},         239         {"Input Mux", "Mic", "Mic Bias"},
220         {"ADC", NULL, "Input Mux"},               240         {"ADC", NULL, "Input Mux"},
221                                                   241 
222         /* inputs */                              242         /* inputs */
223         {"Line Input", NULL, "LLINEIN"},          243         {"Line Input", NULL, "LLINEIN"},
224         {"Line Input", NULL, "RLINEIN"},          244         {"Line Input", NULL, "RLINEIN"},
225         {"Mic Bias", NULL, "MICIN"},              245         {"Mic Bias", NULL, "MICIN"},
226 };                                                246 };
227                                                   247 
228 struct _coeff_div {                               248 struct _coeff_div {
229         u32 mclk;                                 249         u32 mclk;
230         u32 rate;                                 250         u32 rate;
231         u16 fs;                                   251         u16 fs;
232         u8 sr:4;                                  252         u8 sr:4;
233         u8 bosr:1;                                253         u8 bosr:1;
234         u8 usb:1;                                 254         u8 usb:1;
235 };                                                255 };
236                                                   256 
237 /* codec mclk clock divider coefficients */       257 /* codec mclk clock divider coefficients */
238 static const struct _coeff_div coeff_div[] = {    258 static const struct _coeff_div coeff_div[] = {
239         /* 48k */                                 259         /* 48k */
240         {12288000, 48000, 256, 0x0, 0x0, 0x0},    260         {12288000, 48000, 256, 0x0, 0x0, 0x0},
241         {18432000, 48000, 384, 0x0, 0x1, 0x0},    261         {18432000, 48000, 384, 0x0, 0x1, 0x0},
242         {12000000, 48000, 250, 0x0, 0x0, 0x1},    262         {12000000, 48000, 250, 0x0, 0x0, 0x1},
243                                                   263 
244         /* 32k */                                 264         /* 32k */
245         {12288000, 32000, 384, 0x6, 0x0, 0x0},    265         {12288000, 32000, 384, 0x6, 0x0, 0x0},
246         {18432000, 32000, 576, 0x6, 0x1, 0x0},    266         {18432000, 32000, 576, 0x6, 0x1, 0x0},
247         {12000000, 32000, 375, 0x6, 0x0, 0x1},    267         {12000000, 32000, 375, 0x6, 0x0, 0x1},
248                                                   268 
249         /* 8k */                                  269         /* 8k */
250         {12288000, 8000, 1536, 0x3, 0x0, 0x0},    270         {12288000, 8000, 1536, 0x3, 0x0, 0x0},
251         {18432000, 8000, 2304, 0x3, 0x1, 0x0},    271         {18432000, 8000, 2304, 0x3, 0x1, 0x0},
252         {11289600, 8000, 1408, 0xb, 0x0, 0x0},    272         {11289600, 8000, 1408, 0xb, 0x0, 0x0},
253         {16934400, 8000, 2112, 0xb, 0x1, 0x0},    273         {16934400, 8000, 2112, 0xb, 0x1, 0x0},
254         {12000000, 8000, 1500, 0x3, 0x0, 0x1},    274         {12000000, 8000, 1500, 0x3, 0x0, 0x1},
255                                                   275 
256         /* 96k */                                 276         /* 96k */
257         {12288000, 96000, 128, 0x7, 0x0, 0x0},    277         {12288000, 96000, 128, 0x7, 0x0, 0x0},
258         {18432000, 96000, 192, 0x7, 0x1, 0x0},    278         {18432000, 96000, 192, 0x7, 0x1, 0x0},
259         {12000000, 96000, 125, 0x7, 0x0, 0x1},    279         {12000000, 96000, 125, 0x7, 0x0, 0x1},
260                                                   280 
261         /* 44.1k */                               281         /* 44.1k */
262         {11289600, 44100, 256, 0x8, 0x0, 0x0},    282         {11289600, 44100, 256, 0x8, 0x0, 0x0},
263         {16934400, 44100, 384, 0x8, 0x1, 0x0},    283         {16934400, 44100, 384, 0x8, 0x1, 0x0},
264         {12000000, 44100, 272, 0x8, 0x1, 0x1},    284         {12000000, 44100, 272, 0x8, 0x1, 0x1},
265                                                   285 
266         /* 88.2k */                               286         /* 88.2k */
267         {11289600, 88200, 128, 0xf, 0x0, 0x0},    287         {11289600, 88200, 128, 0xf, 0x0, 0x0},
268         {16934400, 88200, 192, 0xf, 0x1, 0x0},    288         {16934400, 88200, 192, 0xf, 0x1, 0x0},
269         {12000000, 88200, 136, 0xf, 0x1, 0x1},    289         {12000000, 88200, 136, 0xf, 0x1, 0x1},
270 };                                                290 };
271                                                   291 
272 /* rates constraints */                           292 /* rates constraints */
273 static const unsigned int wm8731_rates_1200000    293 static const unsigned int wm8731_rates_12000000[] = {
274         8000, 32000, 44100, 48000, 96000, 8820    294         8000, 32000, 44100, 48000, 96000, 88200,
275 };                                                295 };
276                                                   296 
277 static const unsigned int wm8731_rates_1228800    297 static const unsigned int wm8731_rates_12288000_18432000[] = {
278         8000, 32000, 48000, 96000,                298         8000, 32000, 48000, 96000,
279 };                                                299 };
280                                                   300 
281 static const unsigned int wm8731_rates_1128960    301 static const unsigned int wm8731_rates_11289600_16934400[] = {
282         8000, 44100, 88200,                       302         8000, 44100, 88200,
283 };                                                303 };
284                                                   304 
285 static const struct snd_pcm_hw_constraint_list    305 static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000 = {
286         .list = wm8731_rates_12000000,            306         .list = wm8731_rates_12000000,
287         .count = ARRAY_SIZE(wm8731_rates_12000    307         .count = ARRAY_SIZE(wm8731_rates_12000000),
288 };                                                308 };
289                                                   309 
290 static const                                      310 static const
291 struct snd_pcm_hw_constraint_list wm8731_const    311 struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000 = {
292         .list = wm8731_rates_12288000_18432000    312         .list = wm8731_rates_12288000_18432000,
293         .count = ARRAY_SIZE(wm8731_rates_12288    313         .count = ARRAY_SIZE(wm8731_rates_12288000_18432000),
294 };                                                314 };
295                                                   315 
296 static const                                      316 static const
297 struct snd_pcm_hw_constraint_list wm8731_const    317 struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400 = {
298         .list = wm8731_rates_11289600_16934400    318         .list = wm8731_rates_11289600_16934400,
299         .count = ARRAY_SIZE(wm8731_rates_11289    319         .count = ARRAY_SIZE(wm8731_rates_11289600_16934400),
300 };                                                320 };
301                                                   321 
302 static inline int get_coeff(int mclk, int rate    322 static inline int get_coeff(int mclk, int rate)
303 {                                                 323 {
304         int i;                                    324         int i;
305                                                   325 
306         for (i = 0; i < ARRAY_SIZE(coeff_div);    326         for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
307                 if (coeff_div[i].rate == rate     327                 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
308                         return i;                 328                         return i;
309         }                                         329         }
310         return 0;                                 330         return 0;
311 }                                                 331 }
312                                                   332 
313 static int wm8731_hw_params(struct snd_pcm_sub    333 static int wm8731_hw_params(struct snd_pcm_substream *substream,
314                             struct snd_pcm_hw_    334                             struct snd_pcm_hw_params *params,
315                             struct snd_soc_dai    335                             struct snd_soc_dai *dai)
316 {                                                 336 {
317         struct snd_soc_component *component =     337         struct snd_soc_component *component = dai->component;
318         struct wm8731_priv *wm8731 = snd_soc_c    338         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
319         u16 iface = snd_soc_component_read(com    339         u16 iface = snd_soc_component_read(component, WM8731_IFACE) & 0xfff3;
320         int i = get_coeff(wm8731->sysclk, para    340         int i = get_coeff(wm8731->sysclk, params_rate(params));
321         u16 srate = (coeff_div[i].sr << 2) |      341         u16 srate = (coeff_div[i].sr << 2) |
322                 (coeff_div[i].bosr << 1) | coe    342                 (coeff_div[i].bosr << 1) | coeff_div[i].usb;
323                                                   343 
324         wm8731->playback_fs = params_rate(para    344         wm8731->playback_fs = params_rate(params);
325                                                   345 
326         snd_soc_component_write(component, WM8    346         snd_soc_component_write(component, WM8731_SRATE, srate);
327                                                   347 
328         /* bit size */                            348         /* bit size */
329         switch (params_width(params)) {           349         switch (params_width(params)) {
330         case 16:                                  350         case 16:
331                 break;                            351                 break;
332         case 20:                                  352         case 20:
333                 iface |= 0x0004;                  353                 iface |= 0x0004;
334                 break;                            354                 break;
335         case 24:                                  355         case 24:
336                 iface |= 0x0008;                  356                 iface |= 0x0008;
337                 break;                            357                 break;
338         case 32:                                  358         case 32:
339                 iface |= 0x000c;                  359                 iface |= 0x000c;
340                 break;                            360                 break;
341         }                                         361         }
342                                                   362 
343         wm8731_set_deemph(component);             363         wm8731_set_deemph(component);
344                                                   364 
345         snd_soc_component_write(component, WM8    365         snd_soc_component_write(component, WM8731_IFACE, iface);
346         return 0;                                 366         return 0;
347 }                                                 367 }
348                                                   368 
349 static int wm8731_mute(struct snd_soc_dai *dai    369 static int wm8731_mute(struct snd_soc_dai *dai, int mute, int direction)
350 {                                                 370 {
351         struct snd_soc_component *component =     371         struct snd_soc_component *component = dai->component;
352         u16 mute_reg = snd_soc_component_read(    372         u16 mute_reg = snd_soc_component_read(component, WM8731_APDIGI) & 0xfff7;
353                                                   373 
354         if (mute)                                 374         if (mute)
355                 snd_soc_component_write(compon    375                 snd_soc_component_write(component, WM8731_APDIGI, mute_reg | 0x8);
356         else                                      376         else
357                 snd_soc_component_write(compon    377                 snd_soc_component_write(component, WM8731_APDIGI, mute_reg);
358         return 0;                                 378         return 0;
359 }                                                 379 }
360                                                   380 
361 static int wm8731_set_dai_sysclk(struct snd_so    381 static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
362                 int clk_id, unsigned int freq,    382                 int clk_id, unsigned int freq, int dir)
363 {                                                 383 {
364         struct snd_soc_component *component =     384         struct snd_soc_component *component = codec_dai->component;
365         struct snd_soc_dapm_context *dapm = sn    385         struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
366         struct wm8731_priv *wm8731 = snd_soc_c    386         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
367                                                   387 
368         switch (clk_id) {                         388         switch (clk_id) {
369         case WM8731_SYSCLK_XTAL:                  389         case WM8731_SYSCLK_XTAL:
370         case WM8731_SYSCLK_MCLK:                  390         case WM8731_SYSCLK_MCLK:
371                 if (wm8731->mclk && clk_set_ra    391                 if (wm8731->mclk && clk_set_rate(wm8731->mclk, freq))
372                         return -EINVAL;           392                         return -EINVAL;
373                 wm8731->sysclk_type = clk_id;     393                 wm8731->sysclk_type = clk_id;
374                 break;                            394                 break;
375         default:                                  395         default:
376                 return -EINVAL;                   396                 return -EINVAL;
377         }                                         397         }
378                                                   398 
379         switch (freq) {                           399         switch (freq) {
380         case 0:                                   400         case 0:
381                 wm8731->constraints = NULL;       401                 wm8731->constraints = NULL;
382                 break;                            402                 break;
383         case 12000000:                            403         case 12000000:
384                 wm8731->constraints = &wm8731_    404                 wm8731->constraints = &wm8731_constraints_12000000;
385                 break;                            405                 break;
386         case 12288000:                            406         case 12288000:
387         case 18432000:                            407         case 18432000:
388                 wm8731->constraints = &wm8731_    408                 wm8731->constraints = &wm8731_constraints_12288000_18432000;
389                 break;                            409                 break;
390         case 16934400:                            410         case 16934400:
391         case 11289600:                            411         case 11289600:
392                 wm8731->constraints = &wm8731_    412                 wm8731->constraints = &wm8731_constraints_11289600_16934400;
393                 break;                            413                 break;
394         default:                                  414         default:
395                 return -EINVAL;                   415                 return -EINVAL;
396         }                                         416         }
397                                                   417 
398         wm8731->sysclk = freq;                    418         wm8731->sysclk = freq;
399                                                   419 
400         snd_soc_dapm_sync(dapm);                  420         snd_soc_dapm_sync(dapm);
401                                                   421 
402         return 0;                                 422         return 0;
403 }                                                 423 }
404                                                   424 
405                                                   425 
406 static int wm8731_set_dai_fmt(struct snd_soc_d    426 static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
407                 unsigned int fmt)                 427                 unsigned int fmt)
408 {                                                 428 {
409         struct snd_soc_component *component =     429         struct snd_soc_component *component = codec_dai->component;
410         u16 iface = 0;                            430         u16 iface = 0;
411                                                   431 
412         switch (fmt & SND_SOC_DAIFMT_CLOCK_PRO !! 432         /* set master/slave audio interface */
413         case SND_SOC_DAIFMT_CBP_CFP:           !! 433         switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
                                                   >> 434         case SND_SOC_DAIFMT_CBM_CFM:
414                 iface |= 0x0040;                  435                 iface |= 0x0040;
415                 break;                            436                 break;
416         case SND_SOC_DAIFMT_CBC_CFC:           !! 437         case SND_SOC_DAIFMT_CBS_CFS:
417                 break;                            438                 break;
418         default:                                  439         default:
419                 return -EINVAL;                   440                 return -EINVAL;
420         }                                         441         }
421                                                   442 
422         /* interface format */                    443         /* interface format */
423         switch (fmt & SND_SOC_DAIFMT_FORMAT_MA    444         switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
424         case SND_SOC_DAIFMT_I2S:                  445         case SND_SOC_DAIFMT_I2S:
425                 iface |= 0x0002;                  446                 iface |= 0x0002;
426                 break;                            447                 break;
427         case SND_SOC_DAIFMT_RIGHT_J:              448         case SND_SOC_DAIFMT_RIGHT_J:
428                 break;                            449                 break;
429         case SND_SOC_DAIFMT_LEFT_J:               450         case SND_SOC_DAIFMT_LEFT_J:
430                 iface |= 0x0001;                  451                 iface |= 0x0001;
431                 break;                            452                 break;
432         case SND_SOC_DAIFMT_DSP_A:                453         case SND_SOC_DAIFMT_DSP_A:
433                 iface |= 0x0013;                  454                 iface |= 0x0013;
434                 break;                            455                 break;
435         case SND_SOC_DAIFMT_DSP_B:                456         case SND_SOC_DAIFMT_DSP_B:
436                 iface |= 0x0003;                  457                 iface |= 0x0003;
437                 break;                            458                 break;
438         default:                                  459         default:
439                 return -EINVAL;                   460                 return -EINVAL;
440         }                                         461         }
441                                                   462 
442         /* clock inversion */                     463         /* clock inversion */
443         switch (fmt & SND_SOC_DAIFMT_INV_MASK)    464         switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
444         case SND_SOC_DAIFMT_NB_NF:                465         case SND_SOC_DAIFMT_NB_NF:
445                 break;                            466                 break;
446         case SND_SOC_DAIFMT_IB_IF:                467         case SND_SOC_DAIFMT_IB_IF:
447                 iface |= 0x0090;                  468                 iface |= 0x0090;
448                 break;                            469                 break;
449         case SND_SOC_DAIFMT_IB_NF:                470         case SND_SOC_DAIFMT_IB_NF:
450                 iface |= 0x0080;                  471                 iface |= 0x0080;
451                 break;                            472                 break;
452         case SND_SOC_DAIFMT_NB_IF:                473         case SND_SOC_DAIFMT_NB_IF:
453                 iface |= 0x0010;                  474                 iface |= 0x0010;
454                 break;                            475                 break;
455         default:                                  476         default:
456                 return -EINVAL;                   477                 return -EINVAL;
457         }                                         478         }
458                                                   479 
459         /* set iface */                           480         /* set iface */
460         snd_soc_component_write(component, WM8    481         snd_soc_component_write(component, WM8731_IFACE, iface);
461         return 0;                                 482         return 0;
462 }                                                 483 }
463                                                   484 
464 static int wm8731_set_bias_level(struct snd_so    485 static int wm8731_set_bias_level(struct snd_soc_component *component,
465                                  enum snd_soc_    486                                  enum snd_soc_bias_level level)
466 {                                                 487 {
467         struct wm8731_priv *wm8731 = snd_soc_c    488         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
468         int ret;                                  489         int ret;
469         u16 reg;                                  490         u16 reg;
470                                                   491 
471         switch (level) {                          492         switch (level) {
472         case SND_SOC_BIAS_ON:                     493         case SND_SOC_BIAS_ON:
473                 if (wm8731->mclk) {               494                 if (wm8731->mclk) {
474                         ret = clk_prepare_enab    495                         ret = clk_prepare_enable(wm8731->mclk);
475                         if (ret)                  496                         if (ret)
476                                 return ret;       497                                 return ret;
477                 }                                 498                 }
478                 break;                            499                 break;
479         case SND_SOC_BIAS_PREPARE:                500         case SND_SOC_BIAS_PREPARE:
480                 break;                            501                 break;
481         case SND_SOC_BIAS_STANDBY:                502         case SND_SOC_BIAS_STANDBY:
482                 if (snd_soc_component_get_bias    503                 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
483                         ret = regulator_bulk_e    504                         ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
484                                                   505                                                     wm8731->supplies);
485                         if (ret != 0)             506                         if (ret != 0)
486                                 return ret;       507                                 return ret;
487                                                   508 
488                         regcache_sync(wm8731->    509                         regcache_sync(wm8731->regmap);
489                 }                                 510                 }
490                                                   511 
491                 /* Clear PWROFF, gate CLKOUT,     512                 /* Clear PWROFF, gate CLKOUT, everything else as-is */
492                 reg = snd_soc_component_read(c    513                 reg = snd_soc_component_read(component, WM8731_PWR) & 0xff7f;
493                 snd_soc_component_write(compon    514                 snd_soc_component_write(component, WM8731_PWR, reg | 0x0040);
494                 break;                            515                 break;
495         case SND_SOC_BIAS_OFF:                    516         case SND_SOC_BIAS_OFF:
496                 if (wm8731->mclk)                 517                 if (wm8731->mclk)
497                         clk_disable_unprepare(    518                         clk_disable_unprepare(wm8731->mclk);
498                 snd_soc_component_write(compon    519                 snd_soc_component_write(component, WM8731_PWR, 0xffff);
499                 regulator_bulk_disable(ARRAY_S    520                 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies),
500                                        wm8731-    521                                        wm8731->supplies);
501                 regcache_mark_dirty(wm8731->re    522                 regcache_mark_dirty(wm8731->regmap);
502                 break;                            523                 break;
503         }                                         524         }
504         return 0;                                 525         return 0;
505 }                                                 526 }
506                                                   527 
507 static int wm8731_startup(struct snd_pcm_subst    528 static int wm8731_startup(struct snd_pcm_substream *substream,
508         struct snd_soc_dai *dai)                  529         struct snd_soc_dai *dai)
509 {                                                 530 {
510         struct wm8731_priv *wm8731 = snd_soc_c    531         struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(dai->component);
511                                                   532 
512         if (wm8731->constraints)                  533         if (wm8731->constraints)
513                 snd_pcm_hw_constraint_list(sub    534                 snd_pcm_hw_constraint_list(substream->runtime, 0,
514                                            SND    535                                            SNDRV_PCM_HW_PARAM_RATE,
515                                            wm8    536                                            wm8731->constraints);
516                                                   537 
517         return 0;                                 538         return 0;
518 }                                                 539 }
519                                                   540 
520 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000    541 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000
521                                                   542 
522 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_L    543 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
523         SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FM    544         SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
524                                                   545 
525 static const struct snd_soc_dai_ops wm8731_dai    546 static const struct snd_soc_dai_ops wm8731_dai_ops = {
526         .startup        = wm8731_startup,         547         .startup        = wm8731_startup,
527         .hw_params      = wm8731_hw_params,       548         .hw_params      = wm8731_hw_params,
528         .mute_stream    = wm8731_mute,            549         .mute_stream    = wm8731_mute,
529         .set_sysclk     = wm8731_set_dai_syscl    550         .set_sysclk     = wm8731_set_dai_sysclk,
530         .set_fmt        = wm8731_set_dai_fmt,     551         .set_fmt        = wm8731_set_dai_fmt,
531         .no_capture_mute = 1,                     552         .no_capture_mute = 1,
532 };                                                553 };
533                                                   554 
534 static struct snd_soc_dai_driver wm8731_dai =     555 static struct snd_soc_dai_driver wm8731_dai = {
535         .name = "wm8731-hifi",                    556         .name = "wm8731-hifi",
536         .playback = {                             557         .playback = {
537                 .stream_name = "Playback",        558                 .stream_name = "Playback",
538                 .channels_min = 1,                559                 .channels_min = 1,
539                 .channels_max = 2,                560                 .channels_max = 2,
540                 .rates = WM8731_RATES,            561                 .rates = WM8731_RATES,
541                 .formats = WM8731_FORMATS,},      562                 .formats = WM8731_FORMATS,},
542         .capture = {                              563         .capture = {
543                 .stream_name = "Capture",         564                 .stream_name = "Capture",
544                 .channels_min = 1,                565                 .channels_min = 1,
545                 .channels_max = 2,                566                 .channels_max = 2,
546                 .rates = WM8731_RATES,            567                 .rates = WM8731_RATES,
547                 .formats = WM8731_FORMATS,},      568                 .formats = WM8731_FORMATS,},
548         .ops = &wm8731_dai_ops,                   569         .ops = &wm8731_dai_ops,
549         .symmetric_rate = 1,                      570         .symmetric_rate = 1,
550 };                                                571 };
551                                                   572 
                                                   >> 573 static int wm8731_request_supplies(struct device *dev,
                                                   >> 574                 struct wm8731_priv *wm8731)
                                                   >> 575 {
                                                   >> 576         int ret = 0, i;
                                                   >> 577 
                                                   >> 578         for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++)
                                                   >> 579                 wm8731->supplies[i].supply = wm8731_supply_names[i];
                                                   >> 580 
                                                   >> 581         ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8731->supplies),
                                                   >> 582                                  wm8731->supplies);
                                                   >> 583         if (ret != 0) {
                                                   >> 584                 dev_err(dev, "Failed to request supplies: %d\n", ret);
                                                   >> 585                 return ret;
                                                   >> 586         }
                                                   >> 587 
                                                   >> 588         ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
                                                   >> 589                                     wm8731->supplies);
                                                   >> 590         if (ret != 0) {
                                                   >> 591                 dev_err(dev, "Failed to enable supplies: %d\n", ret);
                                                   >> 592                 return ret;
                                                   >> 593         }
                                                   >> 594 
                                                   >> 595         return 0;
                                                   >> 596 }
                                                   >> 597 
                                                   >> 598 static int wm8731_hw_init(struct device *dev, struct wm8731_priv *wm8731)
                                                   >> 599 {
                                                   >> 600         int ret = 0;
                                                   >> 601 
                                                   >> 602         ret = wm8731_reset(wm8731->regmap);
                                                   >> 603         if (ret < 0) {
                                                   >> 604                 dev_err(dev, "Failed to issue reset: %d\n", ret);
                                                   >> 605                 goto err;
                                                   >> 606         }
                                                   >> 607 
                                                   >> 608         /* Clear POWEROFF, keep everything else disabled */
                                                   >> 609         regmap_write(wm8731->regmap, WM8731_PWR, 0x7f);
                                                   >> 610 
                                                   >> 611         /* Latch the update bits */
                                                   >> 612         regmap_update_bits(wm8731->regmap, WM8731_LOUT1V, 0x100, 0);
                                                   >> 613         regmap_update_bits(wm8731->regmap, WM8731_ROUT1V, 0x100, 0);
                                                   >> 614         regmap_update_bits(wm8731->regmap, WM8731_LINVOL, 0x100, 0);
                                                   >> 615         regmap_update_bits(wm8731->regmap, WM8731_RINVOL, 0x100, 0);
                                                   >> 616 
                                                   >> 617         /* Disable bypass path by default */
                                                   >> 618         regmap_update_bits(wm8731->regmap, WM8731_APANA, 0x8, 0);
                                                   >> 619 
                                                   >> 620         regcache_mark_dirty(wm8731->regmap);
                                                   >> 621 
                                                   >> 622 err:
                                                   >> 623         return ret;
                                                   >> 624 }
                                                   >> 625 
552 static const struct snd_soc_component_driver s    626 static const struct snd_soc_component_driver soc_component_dev_wm8731 = {
553         .set_bias_level         = wm8731_set_b    627         .set_bias_level         = wm8731_set_bias_level,
554         .controls               = wm8731_snd_c    628         .controls               = wm8731_snd_controls,
555         .num_controls           = ARRAY_SIZE(w    629         .num_controls           = ARRAY_SIZE(wm8731_snd_controls),
556         .dapm_widgets           = wm8731_dapm_    630         .dapm_widgets           = wm8731_dapm_widgets,
557         .num_dapm_widgets       = ARRAY_SIZE(w    631         .num_dapm_widgets       = ARRAY_SIZE(wm8731_dapm_widgets),
558         .dapm_routes            = wm8731_inter    632         .dapm_routes            = wm8731_intercon,
559         .num_dapm_routes        = ARRAY_SIZE(w    633         .num_dapm_routes        = ARRAY_SIZE(wm8731_intercon),
560         .suspend_bias_off       = 1,              634         .suspend_bias_off       = 1,
561         .idle_bias_on           = 1,              635         .idle_bias_on           = 1,
562         .use_pmdown_time        = 1,              636         .use_pmdown_time        = 1,
563         .endianness             = 1,              637         .endianness             = 1,
                                                   >> 638         .non_legacy_dai_naming  = 1,
564 };                                                639 };
565                                                   640 
566 int wm8731_init(struct device *dev, struct wm8 !! 641 static const struct of_device_id wm8731_of_match[] = {
                                                   >> 642         { .compatible = "wlf,wm8731", },
                                                   >> 643         { }
                                                   >> 644 };
                                                   >> 645 
                                                   >> 646 MODULE_DEVICE_TABLE(of, wm8731_of_match);
                                                   >> 647 
                                                   >> 648 static const struct regmap_config wm8731_regmap = {
                                                   >> 649         .reg_bits = 7,
                                                   >> 650         .val_bits = 9,
                                                   >> 651 
                                                   >> 652         .max_register = WM8731_RESET,
                                                   >> 653         .volatile_reg = wm8731_volatile,
                                                   >> 654 
                                                   >> 655         .cache_type = REGCACHE_RBTREE,
                                                   >> 656         .reg_defaults = wm8731_reg_defaults,
                                                   >> 657         .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults),
                                                   >> 658 };
                                                   >> 659 
                                                   >> 660 #if defined(CONFIG_SPI_MASTER)
                                                   >> 661 static int wm8731_spi_probe(struct spi_device *spi)
567 {                                                 662 {
568         int ret = 0, i;                        !! 663         struct wm8731_priv *wm8731;
                                                   >> 664         int ret;
569                                                   665 
570         wm8731->mclk = devm_clk_get(dev, "mclk !! 666         wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL);
                                                   >> 667         if (wm8731 == NULL)
                                                   >> 668                 return -ENOMEM;
                                                   >> 669 
                                                   >> 670         wm8731->mclk = devm_clk_get(&spi->dev, "mclk");
571         if (IS_ERR(wm8731->mclk)) {               671         if (IS_ERR(wm8731->mclk)) {
572                 ret = PTR_ERR(wm8731->mclk);      672                 ret = PTR_ERR(wm8731->mclk);
573                 if (ret == -ENOENT) {             673                 if (ret == -ENOENT) {
574                         wm8731->mclk = NULL;      674                         wm8731->mclk = NULL;
575                         dev_warn(dev, "Assumin !! 675                         dev_warn(&spi->dev, "Assuming static MCLK\n");
576                 } else {                          676                 } else {
577                         dev_err(dev, "Failed t !! 677                         dev_err(&spi->dev, "Failed to get MCLK: %d\n",
                                                   >> 678                                 ret);
578                         return ret;               679                         return ret;
579                 }                                 680                 }
580         }                                         681         }
581                                                   682 
582         mutex_init(&wm8731->lock);                683         mutex_init(&wm8731->lock);
583                                                   684 
584         for (i = 0; i < ARRAY_SIZE(wm8731->sup !! 685         spi_set_drvdata(spi, wm8731);
585                 wm8731->supplies[i].supply = w << 
586                                                   686 
587         ret = devm_regulator_bulk_get(dev, ARR !! 687         ret = wm8731_request_supplies(&spi->dev, wm8731);
588                                  wm8731->suppl !! 688         if (ret != 0)
589         if (ret != 0) {                        !! 689                 return ret;
590                 dev_err(dev, "Failed to reques !! 690 
                                                   >> 691         wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
                                                   >> 692         if (IS_ERR(wm8731->regmap)) {
                                                   >> 693                 ret = PTR_ERR(wm8731->regmap);
                                                   >> 694                 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
                                                   >> 695                         ret);
591                 return ret;                       696                 return ret;
592         }                                         697         }
593                                                   698 
594         ret = regulator_bulk_enable(ARRAY_SIZE !! 699         ret = wm8731_hw_init(&spi->dev, wm8731);
595                                     wm8731->su !! 700         if (ret != 0)
                                                   >> 701                 return ret;
                                                   >> 702 
                                                   >> 703         ret = devm_snd_soc_register_component(&spi->dev,
                                                   >> 704                         &soc_component_dev_wm8731, &wm8731_dai, 1);
596         if (ret != 0) {                           705         if (ret != 0) {
597                 dev_err(dev, "Failed to enable !! 706                 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret);
598                 return ret;                       707                 return ret;
599         }                                         708         }
600                                                   709 
601         ret = wm8731_reset(wm8731->regmap);    !! 710         return 0;
602         if (ret < 0) {                         !! 711 }
603                 dev_err(dev, "Failed to issue  !! 712 
604                 goto err_regulator_enable;     !! 713 static struct spi_driver wm8731_spi_driver = {
                                                   >> 714         .driver = {
                                                   >> 715                 .name   = "wm8731",
                                                   >> 716                 .of_match_table = wm8731_of_match,
                                                   >> 717         },
                                                   >> 718         .probe          = wm8731_spi_probe,
                                                   >> 719 };
                                                   >> 720 #endif /* CONFIG_SPI_MASTER */
                                                   >> 721 
                                                   >> 722 #if IS_ENABLED(CONFIG_I2C)
                                                   >> 723 static int wm8731_i2c_probe(struct i2c_client *i2c,
                                                   >> 724                             const struct i2c_device_id *id)
                                                   >> 725 {
                                                   >> 726         struct wm8731_priv *wm8731;
                                                   >> 727         int ret;
                                                   >> 728 
                                                   >> 729         wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv),
                                                   >> 730                               GFP_KERNEL);
                                                   >> 731         if (wm8731 == NULL)
                                                   >> 732                 return -ENOMEM;
                                                   >> 733 
                                                   >> 734         wm8731->mclk = devm_clk_get(&i2c->dev, "mclk");
                                                   >> 735         if (IS_ERR(wm8731->mclk)) {
                                                   >> 736                 ret = PTR_ERR(wm8731->mclk);
                                                   >> 737                 if (ret == -ENOENT) {
                                                   >> 738                         wm8731->mclk = NULL;
                                                   >> 739                         dev_warn(&i2c->dev, "Assuming static MCLK\n");
                                                   >> 740                 } else {
                                                   >> 741                         dev_err(&i2c->dev, "Failed to get MCLK: %d\n",
                                                   >> 742                                 ret);
                                                   >> 743                         return ret;
                                                   >> 744                 }
605         }                                         745         }
606                                                   746 
607         /* Clear POWEROFF, keep everything els !! 747         mutex_init(&wm8731->lock);
608         regmap_write(wm8731->regmap, WM8731_PW << 
609                                                   748 
610         /* Latch the update bits */            !! 749         i2c_set_clientdata(i2c, wm8731);
611         regmap_update_bits(wm8731->regmap, WM8 << 
612         regmap_update_bits(wm8731->regmap, WM8 << 
613         regmap_update_bits(wm8731->regmap, WM8 << 
614         regmap_update_bits(wm8731->regmap, WM8 << 
615                                                   750 
616         /* Disable bypass path by default */   !! 751         ret = wm8731_request_supplies(&i2c->dev, wm8731);
617         regmap_update_bits(wm8731->regmap, WM8 !! 752         if (ret != 0)
                                                   >> 753                 return ret;
618                                                   754 
619         regcache_mark_dirty(wm8731->regmap);   !! 755         wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
                                                   >> 756         if (IS_ERR(wm8731->regmap)) {
                                                   >> 757                 ret = PTR_ERR(wm8731->regmap);
                                                   >> 758                 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
                                                   >> 759                         ret);
                                                   >> 760                 goto err_regulator_enable;
                                                   >> 761         }
                                                   >> 762 
                                                   >> 763         ret = wm8731_hw_init(&i2c->dev, wm8731);
                                                   >> 764         if (ret != 0)
                                                   >> 765                 goto err_regulator_enable;
620                                                   766 
621         ret = devm_snd_soc_register_component( !! 767         ret = devm_snd_soc_register_component(&i2c->dev,
622                         &soc_component_dev_wm8    768                         &soc_component_dev_wm8731, &wm8731_dai, 1);
623         if (ret != 0) {                           769         if (ret != 0) {
624                 dev_err(dev, "Failed to regist !! 770                 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
625                 goto err_regulator_enable;        771                 goto err_regulator_enable;
626         }                                         772         }
627                                                   773 
628         return 0;                                 774         return 0;
629                                                   775 
630 err_regulator_enable:                             776 err_regulator_enable:
631         /* Regulators will be enabled by bias     777         /* Regulators will be enabled by bias management */
632         regulator_bulk_disable(ARRAY_SIZE(wm87    778         regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
633                                                   779 
634         return ret;                               780         return ret;
635 }                                                 781 }
636 EXPORT_SYMBOL_GPL(wm8731_init);                << 
637                                                << 
638 const struct regmap_config wm8731_regmap = {   << 
639         .reg_bits = 7,                         << 
640         .val_bits = 9,                         << 
641                                                   782 
642         .max_register = WM8731_RESET,          !! 783 static int wm8731_i2c_remove(struct i2c_client *client)
643         .volatile_reg = wm8731_volatile,       !! 784 {
                                                   >> 785         return 0;
                                                   >> 786 }
644                                                   787 
645         .cache_type = REGCACHE_MAPLE,          !! 788 static const struct i2c_device_id wm8731_i2c_id[] = {
646         .reg_defaults = wm8731_reg_defaults,   !! 789         { "wm8731", 0 },
647         .num_reg_defaults = ARRAY_SIZE(wm8731_ !! 790         { }
                                                   >> 791 };
                                                   >> 792 MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
                                                   >> 793 
                                                   >> 794 static struct i2c_driver wm8731_i2c_driver = {
                                                   >> 795         .driver = {
                                                   >> 796                 .name = "wm8731",
                                                   >> 797                 .of_match_table = wm8731_of_match,
                                                   >> 798         },
                                                   >> 799         .probe =    wm8731_i2c_probe,
                                                   >> 800         .remove =   wm8731_i2c_remove,
                                                   >> 801         .id_table = wm8731_i2c_id,
648 };                                                802 };
649 EXPORT_SYMBOL_GPL(wm8731_regmap);              !! 803 #endif
                                                   >> 804 
                                                   >> 805 static int __init wm8731_modinit(void)
                                                   >> 806 {
                                                   >> 807         int ret = 0;
                                                   >> 808 #if IS_ENABLED(CONFIG_I2C)
                                                   >> 809         ret = i2c_add_driver(&wm8731_i2c_driver);
                                                   >> 810         if (ret != 0) {
                                                   >> 811                 printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n",
                                                   >> 812                        ret);
                                                   >> 813         }
                                                   >> 814 #endif
                                                   >> 815 #if defined(CONFIG_SPI_MASTER)
                                                   >> 816         ret = spi_register_driver(&wm8731_spi_driver);
                                                   >> 817         if (ret != 0) {
                                                   >> 818                 printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n",
                                                   >> 819                        ret);
                                                   >> 820         }
                                                   >> 821 #endif
                                                   >> 822         return ret;
                                                   >> 823 }
                                                   >> 824 module_init(wm8731_modinit);
                                                   >> 825 
                                                   >> 826 static void __exit wm8731_exit(void)
                                                   >> 827 {
                                                   >> 828 #if IS_ENABLED(CONFIG_I2C)
                                                   >> 829         i2c_del_driver(&wm8731_i2c_driver);
                                                   >> 830 #endif
                                                   >> 831 #if defined(CONFIG_SPI_MASTER)
                                                   >> 832         spi_unregister_driver(&wm8731_spi_driver);
                                                   >> 833 #endif
                                                   >> 834 }
                                                   >> 835 module_exit(wm8731_exit);
650                                                   836 
651 MODULE_DESCRIPTION("ASoC WM8731 driver");         837 MODULE_DESCRIPTION("ASoC WM8731 driver");
652 MODULE_AUTHOR("Richard Purdie");                  838 MODULE_AUTHOR("Richard Purdie");
653 MODULE_LICENSE("GPL");                            839 MODULE_LICENSE("GPL");
654                                                   840 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php