2 * Common code for ADAU1X61 and ADAU1X81 codecs
4 * Copyright 2011-2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 * Licensed under the GPL-2 or later.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/pcm_params.h>
17 #include <sound/soc.h>
18 #include <sound/tlv.h>
19 #include <linux/gcd.h>
20 #include <linux/i2c.h>
21 #include <linux/spi/spi.h>
22 #include <linux/regmap.h>
27 static const char * const adau17x1_capture_mixer_boost_text
[] = {
28 "Normal operation", "Boost Level 1", "Boost Level 2", "Boost Level 3",
31 static SOC_ENUM_SINGLE_DECL(adau17x1_capture_boost_enum
,
32 ADAU17X1_REC_POWER_MGMT
, 5, adau17x1_capture_mixer_boost_text
);
34 static const char * const adau17x1_mic_bias_mode_text
[] = {
35 "Normal operation", "High performance",
38 static SOC_ENUM_SINGLE_DECL(adau17x1_mic_bias_mode_enum
,
39 ADAU17X1_MICBIAS
, 3, adau17x1_mic_bias_mode_text
);
41 static const DECLARE_TLV_DB_MINMAX(adau17x1_digital_tlv
, -9563, 0);
43 static const struct snd_kcontrol_new adau17x1_controls
[] = {
44 SOC_DOUBLE_R_TLV("Digital Capture Volume",
45 ADAU17X1_LEFT_INPUT_DIGITAL_VOL
,
46 ADAU17X1_RIGHT_INPUT_DIGITAL_VOL
,
47 0, 0xff, 1, adau17x1_digital_tlv
),
48 SOC_DOUBLE_R_TLV("Digital Playback Volume", ADAU17X1_DAC_CONTROL1
,
49 ADAU17X1_DAC_CONTROL2
, 0, 0xff, 1, adau17x1_digital_tlv
),
51 SOC_SINGLE("ADC High Pass Filter Switch", ADAU17X1_ADC_CONTROL
,
53 SOC_SINGLE("Playback De-emphasis Switch", ADAU17X1_DAC_CONTROL0
,
56 SOC_ENUM("Capture Boost", adau17x1_capture_boost_enum
),
58 SOC_ENUM("Mic Bias Mode", adau17x1_mic_bias_mode_enum
),
61 static int adau17x1_pll_event(struct snd_soc_dapm_widget
*w
,
62 struct snd_kcontrol
*kcontrol
, int event
)
64 struct adau
*adau
= snd_soc_codec_get_drvdata(w
->codec
);
67 if (SND_SOC_DAPM_EVENT_ON(event
)) {
68 adau
->pll_regs
[5] = 1;
70 adau
->pll_regs
[5] = 0;
71 /* Bypass the PLL when disabled, otherwise registers will become
73 regmap_update_bits(adau
->regmap
, ADAU17X1_CLOCK_CONTROL
,
74 ADAU17X1_CLOCK_CONTROL_CORECLK_SRC_PLL
, 0);
77 /* The PLL register is 6 bytes long and can only be written at once. */
78 ret
= regmap_raw_write(adau
->regmap
, ADAU17X1_PLL_CONTROL
,
79 adau
->pll_regs
, ARRAY_SIZE(adau
->pll_regs
));
81 if (SND_SOC_DAPM_EVENT_ON(event
)) {
83 regmap_update_bits(adau
->regmap
, ADAU17X1_CLOCK_CONTROL
,
84 ADAU17X1_CLOCK_CONTROL_CORECLK_SRC_PLL
,
85 ADAU17X1_CLOCK_CONTROL_CORECLK_SRC_PLL
);
91 static const char * const adau17x1_mono_stereo_text
[] = {
93 "Mono Left Channel (L+R)",
94 "Mono Right Channel (L+R)",
98 static SOC_ENUM_SINGLE_DECL(adau17x1_dac_mode_enum
,
99 ADAU17X1_DAC_CONTROL0
, 6, adau17x1_mono_stereo_text
);
101 static const struct snd_kcontrol_new adau17x1_dac_mode_mux
=
102 SOC_DAPM_ENUM("DAC Mono-Stereo-Mode", adau17x1_dac_mode_enum
);
104 static const struct snd_soc_dapm_widget adau17x1_dapm_widgets
[] = {
105 SND_SOC_DAPM_SUPPLY_S("PLL", 3, SND_SOC_NOPM
, 0, 0, adau17x1_pll_event
,
106 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
108 SND_SOC_DAPM_SUPPLY("AIFCLK", SND_SOC_NOPM
, 0, 0, NULL
, 0),
110 SND_SOC_DAPM_SUPPLY("MICBIAS", ADAU17X1_MICBIAS
, 0, 0, NULL
, 0),
112 SND_SOC_DAPM_SUPPLY("Left Playback Enable", ADAU17X1_PLAY_POWER_MGMT
,
114 SND_SOC_DAPM_SUPPLY("Right Playback Enable", ADAU17X1_PLAY_POWER_MGMT
,
117 SND_SOC_DAPM_MUX("Left DAC Mode Mux", SND_SOC_NOPM
, 0, 0,
118 &adau17x1_dac_mode_mux
),
119 SND_SOC_DAPM_MUX("Right DAC Mode Mux", SND_SOC_NOPM
, 0, 0,
120 &adau17x1_dac_mode_mux
),
122 SND_SOC_DAPM_ADC("Left Decimator", NULL
, ADAU17X1_ADC_CONTROL
, 0, 0),
123 SND_SOC_DAPM_ADC("Right Decimator", NULL
, ADAU17X1_ADC_CONTROL
, 1, 0),
124 SND_SOC_DAPM_DAC("Left DAC", NULL
, ADAU17X1_DAC_CONTROL0
, 0, 0),
125 SND_SOC_DAPM_DAC("Right DAC", NULL
, ADAU17X1_DAC_CONTROL0
, 1, 0),
128 static const struct snd_soc_dapm_route adau17x1_dapm_routes
[] = {
129 { "Left Decimator", NULL
, "SYSCLK" },
130 { "Right Decimator", NULL
, "SYSCLK" },
131 { "Left DAC", NULL
, "SYSCLK" },
132 { "Right DAC", NULL
, "SYSCLK" },
133 { "Capture", NULL
, "SYSCLK" },
134 { "Playback", NULL
, "SYSCLK" },
136 { "Left DAC", NULL
, "Left DAC Mode Mux" },
137 { "Right DAC", NULL
, "Right DAC Mode Mux" },
139 { "Capture", NULL
, "AIFCLK" },
140 { "Playback", NULL
, "AIFCLK" },
143 static const struct snd_soc_dapm_route adau17x1_dapm_pll_route
= {
144 "SYSCLK", NULL
, "PLL",
148 * The MUX register for the Capture and Playback MUXs selects either DSP as
149 * source/destination or one of the TDM slots. The TDM slot is selected via
150 * snd_soc_dai_set_tdm_slot(), so we only expose whether to go to the DSP or
151 * directly to the DAI interface with this control.
153 static int adau17x1_dsp_mux_enum_put(struct snd_kcontrol
*kcontrol
,
154 struct snd_ctl_elem_value
*ucontrol
)
156 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
157 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
158 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
159 struct snd_soc_dapm_update update
;
160 unsigned int stream
= e
->shift_l
;
161 unsigned int val
, change
;
164 if (ucontrol
->value
.enumerated
.item
[0] >= e
->items
)
167 switch (ucontrol
->value
.enumerated
.item
[0]) {
170 adau
->dsp_bypass
[stream
] = false;
173 val
= (adau
->tdm_slot
[stream
] * 2) + 1;
174 adau
->dsp_bypass
[stream
] = true;
178 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
179 reg
= ADAU17X1_SERIAL_INPUT_ROUTE
;
181 reg
= ADAU17X1_SERIAL_OUTPUT_ROUTE
;
183 change
= snd_soc_test_bits(codec
, reg
, 0xff, val
);
185 update
.kcontrol
= kcontrol
;
190 snd_soc_dapm_mux_update_power(&codec
->dapm
, kcontrol
,
191 ucontrol
->value
.enumerated
.item
[0], e
, &update
);
197 static int adau17x1_dsp_mux_enum_get(struct snd_kcontrol
*kcontrol
,
198 struct snd_ctl_elem_value
*ucontrol
)
200 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
201 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
202 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
203 unsigned int stream
= e
->shift_l
;
204 unsigned int reg
, val
;
207 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
208 reg
= ADAU17X1_SERIAL_INPUT_ROUTE
;
210 reg
= ADAU17X1_SERIAL_OUTPUT_ROUTE
;
212 ret
= regmap_read(adau
->regmap
, reg
, &val
);
218 ucontrol
->value
.enumerated
.item
[0] = val
;
223 #define DECLARE_ADAU17X1_DSP_MUX_CTRL(_name, _label, _stream, _text) \
224 const struct snd_kcontrol_new _name = \
225 SOC_DAPM_ENUM_EXT(_label, (const struct soc_enum)\
226 SOC_ENUM_SINGLE(SND_SOC_NOPM, _stream, \
227 ARRAY_SIZE(_text), _text), \
228 adau17x1_dsp_mux_enum_get, adau17x1_dsp_mux_enum_put)
230 static const char * const adau17x1_dac_mux_text
[] = {
235 static const char * const adau17x1_capture_mux_text
[] = {
240 static DECLARE_ADAU17X1_DSP_MUX_CTRL(adau17x1_dac_mux
, "DAC Playback Mux",
241 SNDRV_PCM_STREAM_PLAYBACK
, adau17x1_dac_mux_text
);
243 static DECLARE_ADAU17X1_DSP_MUX_CTRL(adau17x1_capture_mux
, "Capture Mux",
244 SNDRV_PCM_STREAM_CAPTURE
, adau17x1_capture_mux_text
);
246 static const struct snd_soc_dapm_widget adau17x1_dsp_dapm_widgets
[] = {
247 SND_SOC_DAPM_PGA("DSP", ADAU17X1_DSP_RUN
, 0, 0, NULL
, 0),
248 SND_SOC_DAPM_SIGGEN("DSP Siggen"),
250 SND_SOC_DAPM_MUX("DAC Playback Mux", SND_SOC_NOPM
, 0, 0,
252 SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM
, 0, 0,
253 &adau17x1_capture_mux
),
256 static const struct snd_soc_dapm_route adau17x1_dsp_dapm_routes
[] = {
257 { "DAC Playback Mux", "DSP", "DSP" },
258 { "DAC Playback Mux", "AIFIN", "Playback" },
260 { "Left DAC Mode Mux", "Stereo", "DAC Playback Mux" },
261 { "Left DAC Mode Mux", "Mono (L+R)", "DAC Playback Mux" },
262 { "Left DAC Mode Mux", "Mono Left Channel (L+R)", "DAC Playback Mux" },
263 { "Right DAC Mode Mux", "Stereo", "DAC Playback Mux" },
264 { "Right DAC Mode Mux", "Mono (L+R)", "DAC Playback Mux" },
265 { "Right DAC Mode Mux", "Mono Right Channel (L+R)", "DAC Playback Mux" },
267 { "Capture Mux", "DSP", "DSP" },
268 { "Capture Mux", "Decimator", "Left Decimator" },
269 { "Capture Mux", "Decimator", "Right Decimator" },
271 { "Capture", NULL
, "Capture Mux" },
273 { "DSP", NULL
, "DSP Siggen" },
275 { "DSP", NULL
, "Left Decimator" },
276 { "DSP", NULL
, "Right Decimator" },
279 static const struct snd_soc_dapm_route adau17x1_no_dsp_dapm_routes
[] = {
280 { "Left DAC Mode Mux", "Stereo", "Playback" },
281 { "Left DAC Mode Mux", "Mono (L+R)", "Playback" },
282 { "Left DAC Mode Mux", "Mono Left Channel (L+R)", "Playback" },
283 { "Right DAC Mode Mux", "Stereo", "Playback" },
284 { "Right DAC Mode Mux", "Mono (L+R)", "Playback" },
285 { "Right DAC Mode Mux", "Mono Right Channel (L+R)", "Playback" },
286 { "Capture", NULL
, "Left Decimator" },
287 { "Capture", NULL
, "Right Decimator" },
290 bool adau17x1_has_dsp(struct adau
*adau
)
292 switch (adau
->type
) {
301 EXPORT_SYMBOL_GPL(adau17x1_has_dsp
);
303 static int adau17x1_hw_params(struct snd_pcm_substream
*substream
,
304 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
306 struct snd_soc_codec
*codec
= dai
->codec
;
307 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
308 unsigned int val
, div
, dsp_div
;
311 if (adau
->clk_src
== ADAU17X1_CLK_SRC_PLL
)
312 freq
= adau
->pll_freq
;
316 if (freq
% params_rate(params
) != 0)
319 switch (freq
/ params_rate(params
)) {
324 case 6144: /* fs / 6 */
328 case 4096: /* fs / 4 */
332 case 3072: /* fs / 3 */
336 case 2048: /* fs / 2 */
340 case 1536: /* fs / 1.5 */
344 case 512: /* fs / 0.5 */
352 regmap_update_bits(adau
->regmap
, ADAU17X1_CONVERTER0
,
353 ADAU17X1_CONVERTER0_CONVSR_MASK
, div
);
354 if (adau17x1_has_dsp(adau
)) {
355 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_SAMPLING_RATE
, div
);
356 regmap_write(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, dsp_div
);
359 if (adau
->dai_fmt
!= SND_SOC_DAIFMT_RIGHT_J
)
362 switch (params_width(params
)) {
364 val
= ADAU17X1_SERIAL_PORT1_DELAY16
;
367 val
= ADAU17X1_SERIAL_PORT1_DELAY8
;
370 val
= ADAU17X1_SERIAL_PORT1_DELAY0
;
376 return regmap_update_bits(adau
->regmap
, ADAU17X1_SERIAL_PORT1
,
377 ADAU17X1_SERIAL_PORT1_DELAY_MASK
, val
);
380 static int adau17x1_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
,
381 int source
, unsigned int freq_in
, unsigned int freq_out
)
383 struct snd_soc_codec
*codec
= dai
->codec
;
384 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
385 unsigned int r
, n
, m
, i
, j
;
389 if (freq_in
< 8000000 || freq_in
> 27000000)
398 if (freq_out
% freq_in
!= 0) {
399 div
= DIV_ROUND_UP(freq_in
, 13500000);
401 r
= freq_out
/ freq_in
;
402 i
= freq_out
% freq_in
;
408 r
= freq_out
/ freq_in
;
413 if (n
> 0xffff || m
> 0xffff || div
> 3 || r
> 8 || r
< 2)
417 adau
->pll_regs
[0] = m
>> 8;
418 adau
->pll_regs
[1] = m
& 0xff;
419 adau
->pll_regs
[2] = n
>> 8;
420 adau
->pll_regs
[3] = n
& 0xff;
421 adau
->pll_regs
[4] = (r
<< 3) | (div
<< 1);
423 adau
->pll_regs
[4] |= 1; /* Fractional mode */
425 /* The PLL register is 6 bytes long and can only be written at once. */
426 ret
= regmap_raw_write(adau
->regmap
, ADAU17X1_PLL_CONTROL
,
427 adau
->pll_regs
, ARRAY_SIZE(adau
->pll_regs
));
431 adau
->pll_freq
= freq_out
;
436 static int adau17x1_set_dai_sysclk(struct snd_soc_dai
*dai
,
437 int clk_id
, unsigned int freq
, int dir
)
439 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
440 struct snd_soc_dapm_context
*dapm
= &dai
->codec
->dapm
;
443 case ADAU17X1_CLK_SRC_MCLK
:
444 case ADAU17X1_CLK_SRC_PLL
:
452 if (adau
->clk_src
!= clk_id
) {
453 if (clk_id
== ADAU17X1_CLK_SRC_PLL
) {
454 snd_soc_dapm_add_routes(dapm
,
455 &adau17x1_dapm_pll_route
, 1);
457 snd_soc_dapm_del_routes(dapm
,
458 &adau17x1_dapm_pll_route
, 1);
462 adau
->clk_src
= clk_id
;
467 static int adau17x1_set_dai_fmt(struct snd_soc_dai
*dai
,
470 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
471 unsigned int ctrl0
, ctrl1
;
474 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
475 case SND_SOC_DAIFMT_CBM_CFM
:
476 ctrl0
= ADAU17X1_SERIAL_PORT0_MASTER
;
479 case SND_SOC_DAIFMT_CBS_CFS
:
481 adau
->master
= false;
487 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
488 case SND_SOC_DAIFMT_I2S
:
490 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY1
;
492 case SND_SOC_DAIFMT_LEFT_J
:
493 case SND_SOC_DAIFMT_RIGHT_J
:
495 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY0
;
497 case SND_SOC_DAIFMT_DSP_A
:
499 ctrl0
|= ADAU17X1_SERIAL_PORT0_PULSE_MODE
;
500 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY1
;
502 case SND_SOC_DAIFMT_DSP_B
:
504 ctrl0
|= ADAU17X1_SERIAL_PORT0_PULSE_MODE
;
505 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY0
;
511 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
512 case SND_SOC_DAIFMT_NB_NF
:
514 case SND_SOC_DAIFMT_IB_NF
:
515 ctrl0
|= ADAU17X1_SERIAL_PORT0_BCLK_POL
;
517 case SND_SOC_DAIFMT_NB_IF
:
518 lrclk_pol
= !lrclk_pol
;
520 case SND_SOC_DAIFMT_IB_IF
:
521 ctrl0
|= ADAU17X1_SERIAL_PORT0_BCLK_POL
;
522 lrclk_pol
= !lrclk_pol
;
529 ctrl0
|= ADAU17X1_SERIAL_PORT0_LRCLK_POL
;
531 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_PORT0
, ctrl0
);
532 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_PORT1
, ctrl1
);
534 adau
->dai_fmt
= fmt
& SND_SOC_DAIFMT_FORMAT_MASK
;
539 static int adau17x1_set_dai_tdm_slot(struct snd_soc_dai
*dai
,
540 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
542 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
543 unsigned int ser_ctrl0
, ser_ctrl1
;
544 unsigned int conv_ctrl0
, conv_ctrl1
;
556 ser_ctrl0
= ADAU17X1_SERIAL_PORT0_STEREO
;
559 ser_ctrl0
= ADAU17X1_SERIAL_PORT0_TDM4
;
562 if (adau
->type
== ADAU1361
)
565 ser_ctrl0
= ADAU17X1_SERIAL_PORT0_TDM8
;
571 switch (slot_width
* slots
) {
573 if (adau
->type
== ADAU1761
)
576 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK32
;
579 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK64
;
582 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK48
;
585 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK128
;
588 if (adau
->type
== ADAU1361
)
591 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK256
;
599 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(1);
600 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 0;
603 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(2);
604 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 1;
607 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(3);
608 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 2;
611 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(4);
612 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 3;
620 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(1);
621 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 0;
624 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(2);
625 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 1;
628 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(3);
629 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 2;
632 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(4);
633 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 3;
639 regmap_update_bits(adau
->regmap
, ADAU17X1_CONVERTER0
,
640 ADAU17X1_CONVERTER0_DAC_PAIR_MASK
, conv_ctrl0
);
641 regmap_update_bits(adau
->regmap
, ADAU17X1_CONVERTER1
,
642 ADAU17X1_CONVERTER1_ADC_PAIR_MASK
, conv_ctrl1
);
643 regmap_update_bits(adau
->regmap
, ADAU17X1_SERIAL_PORT0
,
644 ADAU17X1_SERIAL_PORT0_TDM_MASK
, ser_ctrl0
);
645 regmap_update_bits(adau
->regmap
, ADAU17X1_SERIAL_PORT1
,
646 ADAU17X1_SERIAL_PORT1_BCLK_MASK
, ser_ctrl1
);
648 if (!adau17x1_has_dsp(adau
))
651 if (adau
->dsp_bypass
[SNDRV_PCM_STREAM_PLAYBACK
]) {
652 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_INPUT_ROUTE
,
653 (adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] * 2) + 1);
656 if (adau
->dsp_bypass
[SNDRV_PCM_STREAM_CAPTURE
]) {
657 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_OUTPUT_ROUTE
,
658 (adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] * 2) + 1);
664 const struct snd_soc_dai_ops adau17x1_dai_ops
= {
665 .hw_params
= adau17x1_hw_params
,
666 .set_sysclk
= adau17x1_set_dai_sysclk
,
667 .set_fmt
= adau17x1_set_dai_fmt
,
668 .set_pll
= adau17x1_set_dai_pll
,
669 .set_tdm_slot
= adau17x1_set_dai_tdm_slot
,
671 EXPORT_SYMBOL_GPL(adau17x1_dai_ops
);
673 int adau17x1_set_micbias_voltage(struct snd_soc_codec
*codec
,
674 enum adau17x1_micbias_voltage micbias
)
676 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
679 case ADAU17X1_MICBIAS_0_90_AVDD
:
680 case ADAU17X1_MICBIAS_0_65_AVDD
:
686 return regmap_write(adau
->regmap
, ADAU17X1_MICBIAS
, micbias
<< 2);
688 EXPORT_SYMBOL_GPL(adau17x1_set_micbias_voltage
);
690 bool adau17x1_readable_register(struct device
*dev
, unsigned int reg
)
693 case ADAU17X1_CLOCK_CONTROL
:
694 case ADAU17X1_PLL_CONTROL
:
695 case ADAU17X1_REC_POWER_MGMT
:
696 case ADAU17X1_MICBIAS
:
697 case ADAU17X1_SERIAL_PORT0
:
698 case ADAU17X1_SERIAL_PORT1
:
699 case ADAU17X1_CONVERTER0
:
700 case ADAU17X1_CONVERTER1
:
701 case ADAU17X1_LEFT_INPUT_DIGITAL_VOL
:
702 case ADAU17X1_RIGHT_INPUT_DIGITAL_VOL
:
703 case ADAU17X1_ADC_CONTROL
:
704 case ADAU17X1_PLAY_POWER_MGMT
:
705 case ADAU17X1_DAC_CONTROL0
:
706 case ADAU17X1_DAC_CONTROL1
:
707 case ADAU17X1_DAC_CONTROL2
:
708 case ADAU17X1_SERIAL_PORT_PAD
:
709 case ADAU17X1_CONTROL_PORT_PAD0
:
710 case ADAU17X1_CONTROL_PORT_PAD1
:
711 case ADAU17X1_DSP_SAMPLING_RATE
:
712 case ADAU17X1_SERIAL_INPUT_ROUTE
:
713 case ADAU17X1_SERIAL_OUTPUT_ROUTE
:
714 case ADAU17X1_DSP_ENABLE
:
715 case ADAU17X1_DSP_RUN
:
716 case ADAU17X1_SERIAL_SAMPLING_RATE
:
723 EXPORT_SYMBOL_GPL(adau17x1_readable_register
);
725 bool adau17x1_volatile_register(struct device
*dev
, unsigned int reg
)
727 /* SigmaDSP parameter and program memory */
732 /* The PLL register is 6 bytes long */
733 case ADAU17X1_PLL_CONTROL
:
734 case ADAU17X1_PLL_CONTROL
+ 1:
735 case ADAU17X1_PLL_CONTROL
+ 2:
736 case ADAU17X1_PLL_CONTROL
+ 3:
737 case ADAU17X1_PLL_CONTROL
+ 4:
738 case ADAU17X1_PLL_CONTROL
+ 5:
746 EXPORT_SYMBOL_GPL(adau17x1_volatile_register
);
748 int adau17x1_load_firmware(struct adau
*adau
, struct device
*dev
,
749 const char *firmware
)
754 ret
= regmap_read(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, &dspsr
);
758 regmap_write(adau
->regmap
, ADAU17X1_DSP_ENABLE
, 1);
759 regmap_write(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, 0xf);
761 ret
= process_sigma_firmware_regmap(dev
, adau
->regmap
, firmware
);
763 regmap_write(adau
->regmap
, ADAU17X1_DSP_ENABLE
, 0);
766 regmap_write(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, dspsr
);
770 EXPORT_SYMBOL_GPL(adau17x1_load_firmware
);
772 int adau17x1_add_widgets(struct snd_soc_codec
*codec
)
774 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
777 ret
= snd_soc_add_codec_controls(codec
, adau17x1_controls
,
778 ARRAY_SIZE(adau17x1_controls
));
781 ret
= snd_soc_dapm_new_controls(&codec
->dapm
, adau17x1_dapm_widgets
,
782 ARRAY_SIZE(adau17x1_dapm_widgets
));
786 if (adau17x1_has_dsp(adau
)) {
787 ret
= snd_soc_dapm_new_controls(&codec
->dapm
,
788 adau17x1_dsp_dapm_widgets
,
789 ARRAY_SIZE(adau17x1_dsp_dapm_widgets
));
793 EXPORT_SYMBOL_GPL(adau17x1_add_widgets
);
795 int adau17x1_add_routes(struct snd_soc_codec
*codec
)
797 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
800 ret
= snd_soc_dapm_add_routes(&codec
->dapm
, adau17x1_dapm_routes
,
801 ARRAY_SIZE(adau17x1_dapm_routes
));
805 if (adau17x1_has_dsp(adau
)) {
806 ret
= snd_soc_dapm_add_routes(&codec
->dapm
,
807 adau17x1_dsp_dapm_routes
,
808 ARRAY_SIZE(adau17x1_dsp_dapm_routes
));
810 ret
= snd_soc_dapm_add_routes(&codec
->dapm
,
811 adau17x1_no_dsp_dapm_routes
,
812 ARRAY_SIZE(adau17x1_no_dsp_dapm_routes
));
816 EXPORT_SYMBOL_GPL(adau17x1_add_routes
);
818 int adau17x1_resume(struct snd_soc_codec
*codec
)
820 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
822 if (adau
->switch_mode
)
823 adau
->switch_mode(codec
->dev
);
825 regcache_sync(adau
->regmap
);
829 EXPORT_SYMBOL_GPL(adau17x1_resume
);
831 int adau17x1_probe(struct device
*dev
, struct regmap
*regmap
,
832 enum adau17x1_type type
, void (*switch_mode
)(struct device
*dev
))
837 return PTR_ERR(regmap
);
839 adau
= devm_kzalloc(dev
, sizeof(*adau
), GFP_KERNEL
);
843 adau
->regmap
= regmap
;
844 adau
->switch_mode
= switch_mode
;
847 dev_set_drvdata(dev
, adau
);
854 EXPORT_SYMBOL_GPL(adau17x1_probe
);
856 MODULE_DESCRIPTION("ASoC ADAU1X61/ADAU1X81 common code");
857 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
858 MODULE_LICENSE("GPL");