2 * es8328.c -- ES8328 ALSA SoC Audio driver
4 * Copyright 2014 Sutajio Ko-Usagi PTE LTD
6 * Author: Sean Cross <xobs@kosagi.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/clk.h>
14 #include <linux/delay.h>
15 #include <linux/of_device.h>
16 #include <linux/module.h>
18 #include <linux/regmap.h>
19 #include <linux/slab.h>
20 #include <linux/regulator/consumer.h>
21 #include <sound/core.h>
22 #include <sound/initval.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/tlv.h>
29 #define ES8328_SYSCLK_RATE_1X 11289600
30 #define ES8328_SYSCLK_RATE_2X 22579200
32 /* Run the codec at 22.5792 or 11.2896 MHz to support these rates */
43 /* regulator supplies for sgtl5000, VDDD is an optional external supply */
44 enum sgtl5000_regulator_supplies
{
52 /* vddd is optional supply */
53 static const char * const supply_names
[ES8328_SUPPLY_NUM
] = {
60 #define ES8328_RATES (SNDRV_PCM_RATE_44100 | \
61 SNDRV_PCM_RATE_22050 | \
63 #define ES8328_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
66 struct regmap
*regmap
;
70 struct regulator_bulk_data supplies
[ES8328_SUPPLY_NUM
];
77 static const char * const adcpol_txt
[] = {"Normal", "L Invert", "R Invert",
79 static SOC_ENUM_SINGLE_DECL(adcpol
,
80 ES8328_ADCCONTROL6
, 6, adcpol_txt
);
82 static const DECLARE_TLV_DB_SCALE(play_tlv
, -3000, 100, 0);
83 static const DECLARE_TLV_DB_SCALE(dac_adc_tlv
, -9600, 50, 0);
84 static const DECLARE_TLV_DB_SCALE(pga_tlv
, 0, 300, 0);
85 static const DECLARE_TLV_DB_SCALE(bypass_tlv
, -1500, 300, 0);
86 static const DECLARE_TLV_DB_SCALE(mic_tlv
, 0, 300, 0);
91 } deemph_settings
[] = {
92 { 0, ES8328_DACCONTROL6_DEEMPH_OFF
},
93 { 32000, ES8328_DACCONTROL6_DEEMPH_32k
},
94 { 44100, ES8328_DACCONTROL6_DEEMPH_44_1k
},
95 { 48000, ES8328_DACCONTROL6_DEEMPH_48k
},
98 static int es8328_set_deemph(struct snd_soc_codec
*codec
)
100 struct es8328_priv
*es8328
= snd_soc_codec_get_drvdata(codec
);
104 * If we're using deemphasis select the nearest available sample
107 if (es8328
->deemph
) {
109 for (i
= 1; i
< ARRAY_SIZE(deemph_settings
); i
++) {
110 if (abs(deemph_settings
[i
].rate
- es8328
->playback_fs
) <
111 abs(deemph_settings
[best
].rate
- es8328
->playback_fs
))
115 val
= deemph_settings
[best
].val
;
117 val
= ES8328_DACCONTROL6_DEEMPH_OFF
;
120 dev_dbg(codec
->dev
, "Set deemphasis %d\n", val
);
122 return snd_soc_update_bits(codec
, ES8328_DACCONTROL6
,
123 ES8328_DACCONTROL6_DEEMPH_MASK
, val
);
126 static int es8328_get_deemph(struct snd_kcontrol
*kcontrol
,
127 struct snd_ctl_elem_value
*ucontrol
)
129 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
130 struct es8328_priv
*es8328
= snd_soc_codec_get_drvdata(codec
);
132 ucontrol
->value
.integer
.value
[0] = es8328
->deemph
;
136 static int es8328_put_deemph(struct snd_kcontrol
*kcontrol
,
137 struct snd_ctl_elem_value
*ucontrol
)
139 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
140 struct es8328_priv
*es8328
= snd_soc_codec_get_drvdata(codec
);
141 unsigned int deemph
= ucontrol
->value
.integer
.value
[0];
147 ret
= es8328_set_deemph(codec
);
151 es8328
->deemph
= deemph
;
158 static const struct snd_kcontrol_new es8328_snd_controls
[] = {
159 SOC_DOUBLE_R_TLV("Capture Digital Volume",
160 ES8328_ADCCONTROL8
, ES8328_ADCCONTROL9
,
161 0, 0xc0, 1, dac_adc_tlv
),
162 SOC_SINGLE("Capture ZC Switch", ES8328_ADCCONTROL7
, 6, 1, 0),
164 SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,
165 es8328_get_deemph
, es8328_put_deemph
),
167 SOC_ENUM("Capture Polarity", adcpol
),
169 SOC_SINGLE_TLV("Left Mixer Left Bypass Volume",
170 ES8328_DACCONTROL17
, 3, 7, 1, bypass_tlv
),
171 SOC_SINGLE_TLV("Left Mixer Right Bypass Volume",
172 ES8328_DACCONTROL19
, 3, 7, 1, bypass_tlv
),
173 SOC_SINGLE_TLV("Right Mixer Left Bypass Volume",
174 ES8328_DACCONTROL18
, 3, 7, 1, bypass_tlv
),
175 SOC_SINGLE_TLV("Right Mixer Right Bypass Volume",
176 ES8328_DACCONTROL20
, 3, 7, 1, bypass_tlv
),
178 SOC_DOUBLE_R_TLV("PCM Volume",
179 ES8328_LDACVOL
, ES8328_RDACVOL
,
180 0, ES8328_DACVOL_MAX
, 1, dac_adc_tlv
),
182 SOC_DOUBLE_R_TLV("Output 1 Playback Volume",
183 ES8328_LOUT1VOL
, ES8328_ROUT1VOL
,
184 0, ES8328_OUT1VOL_MAX
, 0, play_tlv
),
186 SOC_DOUBLE_R_TLV("Output 2 Playback Volume",
187 ES8328_LOUT2VOL
, ES8328_ROUT2VOL
,
188 0, ES8328_OUT2VOL_MAX
, 0, play_tlv
),
190 SOC_DOUBLE_TLV("Mic PGA Volume", ES8328_ADCCONTROL1
,
191 4, 0, 8, 0, mic_tlv
),
198 static const char * const es8328_line_texts
[] = {
199 "Line 1", "Line 2", "PGA", "Differential"};
201 static const struct soc_enum es8328_lline_enum
=
202 SOC_ENUM_SINGLE(ES8328_DACCONTROL16
, 3,
203 ARRAY_SIZE(es8328_line_texts
),
205 static const struct snd_kcontrol_new es8328_left_line_controls
=
206 SOC_DAPM_ENUM("Route", es8328_lline_enum
);
208 static const struct soc_enum es8328_rline_enum
=
209 SOC_ENUM_SINGLE(ES8328_DACCONTROL16
, 0,
210 ARRAY_SIZE(es8328_line_texts
),
212 static const struct snd_kcontrol_new es8328_right_line_controls
=
213 SOC_DAPM_ENUM("Route", es8328_lline_enum
);
216 static const struct snd_kcontrol_new es8328_left_mixer_controls
[] = {
217 SOC_DAPM_SINGLE("Playback Switch", ES8328_DACCONTROL17
, 7, 1, 0),
218 SOC_DAPM_SINGLE("Left Bypass Switch", ES8328_DACCONTROL17
, 6, 1, 0),
219 SOC_DAPM_SINGLE("Right Playback Switch", ES8328_DACCONTROL18
, 7, 1, 0),
220 SOC_DAPM_SINGLE("Right Bypass Switch", ES8328_DACCONTROL18
, 6, 1, 0),
224 static const struct snd_kcontrol_new es8328_right_mixer_controls
[] = {
225 SOC_DAPM_SINGLE("Left Playback Switch", ES8328_DACCONTROL19
, 7, 1, 0),
226 SOC_DAPM_SINGLE("Left Bypass Switch", ES8328_DACCONTROL19
, 6, 1, 0),
227 SOC_DAPM_SINGLE("Playback Switch", ES8328_DACCONTROL20
, 7, 1, 0),
228 SOC_DAPM_SINGLE("Right Bypass Switch", ES8328_DACCONTROL20
, 6, 1, 0),
231 static const char * const es8328_pga_sel
[] = {
232 "Line 1", "Line 2", "Line 3", "Differential"};
235 static const struct soc_enum es8328_lpga_enum
=
236 SOC_ENUM_SINGLE(ES8328_ADCCONTROL2
, 6,
237 ARRAY_SIZE(es8328_pga_sel
),
239 static const struct snd_kcontrol_new es8328_left_pga_controls
=
240 SOC_DAPM_ENUM("Route", es8328_lpga_enum
);
243 static const struct soc_enum es8328_rpga_enum
=
244 SOC_ENUM_SINGLE(ES8328_ADCCONTROL2
, 4,
245 ARRAY_SIZE(es8328_pga_sel
),
247 static const struct snd_kcontrol_new es8328_right_pga_controls
=
248 SOC_DAPM_ENUM("Route", es8328_rpga_enum
);
250 /* Differential Mux */
251 static const char * const es8328_diff_sel
[] = {"Line 1", "Line 2"};
252 static SOC_ENUM_SINGLE_DECL(diffmux
,
253 ES8328_ADCCONTROL3
, 7, es8328_diff_sel
);
254 static const struct snd_kcontrol_new es8328_diffmux_controls
=
255 SOC_DAPM_ENUM("Route", diffmux
);
258 static const char * const es8328_mono_mux
[] = {"Stereo", "Mono (Left)",
259 "Mono (Right)", "Digital Mono"};
260 static SOC_ENUM_SINGLE_DECL(monomux
,
261 ES8328_ADCCONTROL3
, 3, es8328_mono_mux
);
262 static const struct snd_kcontrol_new es8328_monomux_controls
=
263 SOC_DAPM_ENUM("Route", monomux
);
265 static const struct snd_soc_dapm_widget es8328_dapm_widgets
[] = {
266 SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM
, 0, 0,
267 &es8328_diffmux_controls
),
268 SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM
, 0, 0,
269 &es8328_monomux_controls
),
270 SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM
, 0, 0,
271 &es8328_monomux_controls
),
273 SND_SOC_DAPM_MUX("Left PGA Mux", ES8328_ADCPOWER
,
274 ES8328_ADCPOWER_AINL_OFF
, 1,
275 &es8328_left_pga_controls
),
276 SND_SOC_DAPM_MUX("Right PGA Mux", ES8328_ADCPOWER
,
277 ES8328_ADCPOWER_AINR_OFF
, 1,
278 &es8328_right_pga_controls
),
280 SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_NOPM
, 0, 0,
281 &es8328_left_line_controls
),
282 SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_NOPM
, 0, 0,
283 &es8328_right_line_controls
),
285 SND_SOC_DAPM_ADC("Right ADC", "Right Capture", ES8328_ADCPOWER
,
286 ES8328_ADCPOWER_ADCR_OFF
, 1),
287 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", ES8328_ADCPOWER
,
288 ES8328_ADCPOWER_ADCL_OFF
, 1),
290 SND_SOC_DAPM_SUPPLY("Mic Bias", ES8328_ADCPOWER
,
291 ES8328_ADCPOWER_MIC_BIAS_OFF
, 1, NULL
, 0),
292 SND_SOC_DAPM_SUPPLY("Mic Bias Gen", ES8328_ADCPOWER
,
293 ES8328_ADCPOWER_ADC_BIAS_GEN_OFF
, 1, NULL
, 0),
295 SND_SOC_DAPM_SUPPLY("DAC STM", ES8328_CHIPPOWER
,
296 ES8328_CHIPPOWER_DACSTM_RESET
, 1, NULL
, 0),
297 SND_SOC_DAPM_SUPPLY("ADC STM", ES8328_CHIPPOWER
,
298 ES8328_CHIPPOWER_ADCSTM_RESET
, 1, NULL
, 0),
300 SND_SOC_DAPM_SUPPLY("DAC DIG", ES8328_CHIPPOWER
,
301 ES8328_CHIPPOWER_DACDIG_OFF
, 1, NULL
, 0),
302 SND_SOC_DAPM_SUPPLY("ADC DIG", ES8328_CHIPPOWER
,
303 ES8328_CHIPPOWER_ADCDIG_OFF
, 1, NULL
, 0),
305 SND_SOC_DAPM_SUPPLY("DAC DLL", ES8328_CHIPPOWER
,
306 ES8328_CHIPPOWER_DACDLL_OFF
, 1, NULL
, 0),
307 SND_SOC_DAPM_SUPPLY("ADC DLL", ES8328_CHIPPOWER
,
308 ES8328_CHIPPOWER_ADCDLL_OFF
, 1, NULL
, 0),
310 SND_SOC_DAPM_SUPPLY("ADC Vref", ES8328_CHIPPOWER
,
311 ES8328_CHIPPOWER_ADCVREF_OFF
, 1, NULL
, 0),
312 SND_SOC_DAPM_SUPPLY("DAC Vref", ES8328_CHIPPOWER
,
313 ES8328_CHIPPOWER_DACVREF_OFF
, 1, NULL
, 0),
315 SND_SOC_DAPM_DAC("Right DAC", "Right Playback", ES8328_DACPOWER
,
316 ES8328_DACPOWER_RDAC_OFF
, 1),
317 SND_SOC_DAPM_DAC("Left DAC", "Left Playback", ES8328_DACPOWER
,
318 ES8328_DACPOWER_LDAC_OFF
, 1),
320 SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM
, 0, 0,
321 &es8328_left_mixer_controls
[0],
322 ARRAY_SIZE(es8328_left_mixer_controls
)),
323 SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM
, 0, 0,
324 &es8328_right_mixer_controls
[0],
325 ARRAY_SIZE(es8328_right_mixer_controls
)),
327 SND_SOC_DAPM_PGA("Right Out 2", ES8328_DACPOWER
,
328 ES8328_DACPOWER_ROUT2_ON
, 0, NULL
, 0),
329 SND_SOC_DAPM_PGA("Left Out 2", ES8328_DACPOWER
,
330 ES8328_DACPOWER_LOUT2_ON
, 0, NULL
, 0),
331 SND_SOC_DAPM_PGA("Right Out 1", ES8328_DACPOWER
,
332 ES8328_DACPOWER_ROUT1_ON
, 0, NULL
, 0),
333 SND_SOC_DAPM_PGA("Left Out 1", ES8328_DACPOWER
,
334 ES8328_DACPOWER_LOUT1_ON
, 0, NULL
, 0),
336 SND_SOC_DAPM_OUTPUT("LOUT1"),
337 SND_SOC_DAPM_OUTPUT("ROUT1"),
338 SND_SOC_DAPM_OUTPUT("LOUT2"),
339 SND_SOC_DAPM_OUTPUT("ROUT2"),
341 SND_SOC_DAPM_INPUT("LINPUT1"),
342 SND_SOC_DAPM_INPUT("LINPUT2"),
343 SND_SOC_DAPM_INPUT("RINPUT1"),
344 SND_SOC_DAPM_INPUT("RINPUT2"),
347 static const struct snd_soc_dapm_route es8328_dapm_routes
[] = {
349 { "Left Line Mux", "Line 1", "LINPUT1" },
350 { "Left Line Mux", "Line 2", "LINPUT2" },
351 { "Left Line Mux", "PGA", "Left PGA Mux" },
352 { "Left Line Mux", "Differential", "Differential Mux" },
354 { "Right Line Mux", "Line 1", "RINPUT1" },
355 { "Right Line Mux", "Line 2", "RINPUT2" },
356 { "Right Line Mux", "PGA", "Right PGA Mux" },
357 { "Right Line Mux", "Differential", "Differential Mux" },
359 { "Left PGA Mux", "Line 1", "LINPUT1" },
360 { "Left PGA Mux", "Line 2", "LINPUT2" },
361 { "Left PGA Mux", "Differential", "Differential Mux" },
363 { "Right PGA Mux", "Line 1", "RINPUT1" },
364 { "Right PGA Mux", "Line 2", "RINPUT2" },
365 { "Right PGA Mux", "Differential", "Differential Mux" },
367 { "Differential Mux", "Line 1", "LINPUT1" },
368 { "Differential Mux", "Line 1", "RINPUT1" },
369 { "Differential Mux", "Line 2", "LINPUT2" },
370 { "Differential Mux", "Line 2", "RINPUT2" },
372 { "Left ADC Mux", "Stereo", "Left PGA Mux" },
373 { "Left ADC Mux", "Mono (Left)", "Left PGA Mux" },
374 { "Left ADC Mux", "Digital Mono", "Left PGA Mux" },
376 { "Right ADC Mux", "Stereo", "Right PGA Mux" },
377 { "Right ADC Mux", "Mono (Right)", "Right PGA Mux" },
378 { "Right ADC Mux", "Digital Mono", "Right PGA Mux" },
380 { "Left ADC", NULL
, "Left ADC Mux" },
381 { "Right ADC", NULL
, "Right ADC Mux" },
383 { "ADC DIG", NULL
, "ADC STM" },
384 { "ADC DIG", NULL
, "ADC Vref" },
385 { "ADC DIG", NULL
, "ADC DLL" },
387 { "Left ADC", NULL
, "ADC DIG" },
388 { "Right ADC", NULL
, "ADC DIG" },
390 { "Mic Bias", NULL
, "Mic Bias Gen" },
392 { "Left Line Mux", "Line 1", "LINPUT1" },
393 { "Left Line Mux", "Line 2", "LINPUT2" },
394 { "Left Line Mux", "PGA", "Left PGA Mux" },
395 { "Left Line Mux", "Differential", "Differential Mux" },
397 { "Right Line Mux", "Line 1", "RINPUT1" },
398 { "Right Line Mux", "Line 2", "RINPUT2" },
399 { "Right Line Mux", "PGA", "Right PGA Mux" },
400 { "Right Line Mux", "Differential", "Differential Mux" },
402 { "Left Out 1", NULL
, "Left DAC" },
403 { "Right Out 1", NULL
, "Right DAC" },
404 { "Left Out 2", NULL
, "Left DAC" },
405 { "Right Out 2", NULL
, "Right DAC" },
407 { "Left Mixer", "Playback Switch", "Left DAC" },
408 { "Left Mixer", "Left Bypass Switch", "Left Line Mux" },
409 { "Left Mixer", "Right Playback Switch", "Right DAC" },
410 { "Left Mixer", "Right Bypass Switch", "Right Line Mux" },
412 { "Right Mixer", "Left Playback Switch", "Left DAC" },
413 { "Right Mixer", "Left Bypass Switch", "Left Line Mux" },
414 { "Right Mixer", "Playback Switch", "Right DAC" },
415 { "Right Mixer", "Right Bypass Switch", "Right Line Mux" },
417 { "DAC DIG", NULL
, "DAC STM" },
418 { "DAC DIG", NULL
, "DAC Vref" },
419 { "DAC DIG", NULL
, "DAC DLL" },
421 { "Left DAC", NULL
, "DAC DIG" },
422 { "Right DAC", NULL
, "DAC DIG" },
424 { "Left Out 1", NULL
, "Left Mixer" },
425 { "LOUT1", NULL
, "Left Out 1" },
426 { "Right Out 1", NULL
, "Right Mixer" },
427 { "ROUT1", NULL
, "Right Out 1" },
429 { "Left Out 2", NULL
, "Left Mixer" },
430 { "LOUT2", NULL
, "Left Out 2" },
431 { "Right Out 2", NULL
, "Right Mixer" },
432 { "ROUT2", NULL
, "Right Out 2" },
435 static int es8328_mute(struct snd_soc_dai
*dai
, int mute
)
437 return snd_soc_update_bits(dai
->codec
, ES8328_DACCONTROL3
,
438 ES8328_DACCONTROL3_DACMUTE
,
439 mute
? ES8328_DACCONTROL3_DACMUTE
: 0);
442 static int es8328_hw_params(struct snd_pcm_substream
*substream
,
443 struct snd_pcm_hw_params
*params
,
444 struct snd_soc_dai
*dai
)
446 struct snd_soc_codec
*codec
= dai
->codec
;
447 struct es8328_priv
*es8328
= snd_soc_codec_get_drvdata(codec
);
453 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
454 reg
= ES8328_DACCONTROL2
;
456 reg
= ES8328_ADCCONTROL5
;
458 clk_rate
= clk_get_rate(es8328
->clk
);
460 if ((clk_rate
!= ES8328_SYSCLK_RATE_1X
) &&
461 (clk_rate
!= ES8328_SYSCLK_RATE_2X
)) {
463 "%s: clock is running at %d Hz, not %d or %d Hz\n",
465 ES8328_SYSCLK_RATE_1X
, ES8328_SYSCLK_RATE_2X
);
469 /* find master mode MCLK to sampling frequency ratio */
470 ratio
= mclk_ratios
[0].rate
;
471 for (i
= 1; i
< ARRAY_SIZE(mclk_ratios
); i
++)
472 if (params_rate(params
) <= mclk_ratios
[i
].rate
)
473 ratio
= mclk_ratios
[i
].ratio
;
475 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
476 es8328
->playback_fs
= params_rate(params
);
477 es8328_set_deemph(codec
);
480 return snd_soc_update_bits(codec
, reg
, ES8328_RATEMASK
, ratio
);
483 static int es8328_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
486 struct snd_soc_codec
*codec
= codec_dai
->codec
;
487 struct es8328_priv
*es8328
= snd_soc_codec_get_drvdata(codec
);
489 u8 mode
= ES8328_DACCONTROL1_DACWL_16
;
491 /* set master/slave audio interface */
492 if ((fmt
& SND_SOC_DAIFMT_MASTER_MASK
) != SND_SOC_DAIFMT_CBM_CFM
)
495 /* interface format */
496 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
497 case SND_SOC_DAIFMT_I2S
:
498 mode
|= ES8328_DACCONTROL1_DACFORMAT_I2S
;
500 case SND_SOC_DAIFMT_RIGHT_J
:
501 mode
|= ES8328_DACCONTROL1_DACFORMAT_RJUST
;
503 case SND_SOC_DAIFMT_LEFT_J
:
504 mode
|= ES8328_DACCONTROL1_DACFORMAT_LJUST
;
510 /* clock inversion */
511 if ((fmt
& SND_SOC_DAIFMT_INV_MASK
) != SND_SOC_DAIFMT_NB_NF
)
514 snd_soc_write(codec
, ES8328_DACCONTROL1
, mode
);
515 snd_soc_write(codec
, ES8328_ADCCONTROL4
, mode
);
517 /* Master serial port mode, with BCLK generated automatically */
518 clk_rate
= clk_get_rate(es8328
->clk
);
519 if (clk_rate
== ES8328_SYSCLK_RATE_1X
)
520 snd_soc_write(codec
, ES8328_MASTERMODE
,
521 ES8328_MASTERMODE_MSC
);
523 snd_soc_write(codec
, ES8328_MASTERMODE
,
524 ES8328_MASTERMODE_MCLKDIV2
|
525 ES8328_MASTERMODE_MSC
);
530 static int es8328_set_bias_level(struct snd_soc_codec
*codec
,
531 enum snd_soc_bias_level level
)
534 case SND_SOC_BIAS_ON
:
537 case SND_SOC_BIAS_PREPARE
:
538 /* VREF, VMID=2x50k, digital enabled */
539 snd_soc_write(codec
, ES8328_CHIPPOWER
, 0);
540 snd_soc_update_bits(codec
, ES8328_CONTROL1
,
541 ES8328_CONTROL1_VMIDSEL_MASK
|
542 ES8328_CONTROL1_ENREF
,
543 ES8328_CONTROL1_VMIDSEL_50k
|
544 ES8328_CONTROL1_ENREF
);
547 case SND_SOC_BIAS_STANDBY
:
548 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
549 snd_soc_update_bits(codec
, ES8328_CONTROL1
,
550 ES8328_CONTROL1_VMIDSEL_MASK
|
551 ES8328_CONTROL1_ENREF
,
552 ES8328_CONTROL1_VMIDSEL_5k
|
553 ES8328_CONTROL1_ENREF
);
559 snd_soc_write(codec
, ES8328_CONTROL2
,
560 ES8328_CONTROL2_OVERCURRENT_ON
|
561 ES8328_CONTROL2_THERMAL_SHUTDOWN_ON
);
563 /* VREF, VMID=2*500k, digital stopped */
564 snd_soc_update_bits(codec
, ES8328_CONTROL1
,
565 ES8328_CONTROL1_VMIDSEL_MASK
|
566 ES8328_CONTROL1_ENREF
,
567 ES8328_CONTROL1_VMIDSEL_500k
|
568 ES8328_CONTROL1_ENREF
);
571 case SND_SOC_BIAS_OFF
:
572 snd_soc_update_bits(codec
, ES8328_CONTROL1
,
573 ES8328_CONTROL1_VMIDSEL_MASK
|
574 ES8328_CONTROL1_ENREF
,
581 static const struct snd_soc_dai_ops es8328_dai_ops
= {
582 .hw_params
= es8328_hw_params
,
583 .digital_mute
= es8328_mute
,
584 .set_fmt
= es8328_set_dai_fmt
,
587 static struct snd_soc_dai_driver es8328_dai
= {
588 .name
= "es8328-hifi-analog",
590 .stream_name
= "Playback",
593 .rates
= ES8328_RATES
,
594 .formats
= ES8328_FORMATS
,
597 .stream_name
= "Capture",
600 .rates
= ES8328_RATES
,
601 .formats
= ES8328_FORMATS
,
603 .ops
= &es8328_dai_ops
,
606 static int es8328_suspend(struct snd_soc_codec
*codec
)
608 struct es8328_priv
*es8328
;
611 es8328
= snd_soc_codec_get_drvdata(codec
);
613 clk_disable_unprepare(es8328
->clk
);
615 ret
= regulator_bulk_disable(ARRAY_SIZE(es8328
->supplies
),
618 dev_err(codec
->dev
, "unable to disable regulators\n");
624 static int es8328_resume(struct snd_soc_codec
*codec
)
626 struct regmap
*regmap
= dev_get_regmap(codec
->dev
, NULL
);
627 struct es8328_priv
*es8328
;
630 es8328
= snd_soc_codec_get_drvdata(codec
);
632 ret
= clk_prepare_enable(es8328
->clk
);
634 dev_err(codec
->dev
, "unable to enable clock\n");
638 ret
= regulator_bulk_enable(ARRAY_SIZE(es8328
->supplies
),
641 dev_err(codec
->dev
, "unable to enable regulators\n");
645 regcache_mark_dirty(regmap
);
646 ret
= regcache_sync(regmap
);
648 dev_err(codec
->dev
, "unable to sync regcache\n");
655 static int es8328_codec_probe(struct snd_soc_codec
*codec
)
657 struct es8328_priv
*es8328
;
660 es8328
= snd_soc_codec_get_drvdata(codec
);
662 ret
= regulator_bulk_enable(ARRAY_SIZE(es8328
->supplies
),
665 dev_err(codec
->dev
, "unable to enable regulators\n");
670 es8328
->clk
= devm_clk_get(codec
->dev
, NULL
);
671 if (IS_ERR(es8328
->clk
)) {
672 dev_err(codec
->dev
, "codec clock missing or invalid\n");
673 ret
= PTR_ERR(es8328
->clk
);
677 ret
= clk_prepare_enable(es8328
->clk
);
679 dev_err(codec
->dev
, "unable to prepare codec clk\n");
686 regulator_bulk_disable(ARRAY_SIZE(es8328
->supplies
),
691 static int es8328_remove(struct snd_soc_codec
*codec
)
693 struct es8328_priv
*es8328
;
695 es8328
= snd_soc_codec_get_drvdata(codec
);
698 clk_disable_unprepare(es8328
->clk
);
700 regulator_bulk_disable(ARRAY_SIZE(es8328
->supplies
),
706 const struct regmap_config es8328_regmap_config
= {
709 .max_register
= ES8328_REG_MAX
,
710 .cache_type
= REGCACHE_RBTREE
,
712 EXPORT_SYMBOL_GPL(es8328_regmap_config
);
714 static struct snd_soc_codec_driver es8328_codec_driver
= {
715 .probe
= es8328_codec_probe
,
716 .suspend
= es8328_suspend
,
717 .resume
= es8328_resume
,
718 .remove
= es8328_remove
,
719 .set_bias_level
= es8328_set_bias_level
,
720 .suspend_bias_off
= true,
722 .controls
= es8328_snd_controls
,
723 .num_controls
= ARRAY_SIZE(es8328_snd_controls
),
724 .dapm_widgets
= es8328_dapm_widgets
,
725 .num_dapm_widgets
= ARRAY_SIZE(es8328_dapm_widgets
),
726 .dapm_routes
= es8328_dapm_routes
,
727 .num_dapm_routes
= ARRAY_SIZE(es8328_dapm_routes
),
730 int es8328_probe(struct device
*dev
, struct regmap
*regmap
)
732 struct es8328_priv
*es8328
;
737 return PTR_ERR(regmap
);
739 es8328
= devm_kzalloc(dev
, sizeof(*es8328
), GFP_KERNEL
);
743 es8328
->regmap
= regmap
;
745 for (i
= 0; i
< ARRAY_SIZE(es8328
->supplies
); i
++)
746 es8328
->supplies
[i
].supply
= supply_names
[i
];
748 ret
= devm_regulator_bulk_get(dev
, ARRAY_SIZE(es8328
->supplies
),
751 dev_err(dev
, "unable to get regulators\n");
755 dev_set_drvdata(dev
, es8328
);
757 return snd_soc_register_codec(dev
,
758 &es8328_codec_driver
, &es8328_dai
, 1);
760 EXPORT_SYMBOL_GPL(es8328_probe
);
762 MODULE_DESCRIPTION("ASoC ES8328 driver");
763 MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
764 MODULE_LICENSE("GPL");